From 432edcc856086e1f93436653331c82169bd4ff4b Mon Sep 17 00:00:00 2001 From: diosmosis Date: Thu, 10 Jul 2014 21:59:25 -0700 Subject: Fixes #5809, change existing SQL to ignore errors that occur when updates are executed more than once, add test for multiple update and allow updates to specify more than one error code to ignore. --- core/Updater.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'core/Updater.php') diff --git a/core/Updater.php b/core/Updater.php index 6d46bbf147..8b272cde66 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -313,12 +313,29 @@ class Updater public static function handleQueryError($e, $updateSql, $errorToIgnore, $file) { if (($errorToIgnore === false) - || !Db::get()->isErrNo($e, $errorToIgnore) + || !self::isDbErrorOneOf($e, $errorToIgnore) ) { $message = $file . ":\nError trying to execute the query '" . $updateSql . "'.\nThe error was: " . $e->getMessage(); throw new UpdaterErrorException($message); } } + + /** + * Returns whether an exception is a DB error with a code in the $errorCodesToIgnore list. + * + * @param int $error + * @param int|int[] $errorCodesToIgnore + */ + public static function isDbErrorOneOf($error, $errorCodesToIgnore) + { + $errorCodesToIgnore = is_array($errorCodesToIgnore) ? $errorCodesToIgnore : array($errorCodesToIgnore); + foreach ($errorCodesToIgnore as $code) { + if (Db::get()->isErrNo($error, $code)) { + return true; + } + } + return false; + } } /** @@ -327,4 +344,4 @@ class Updater */ class UpdaterErrorException extends \Exception { -} +} \ No newline at end of file -- cgit v1.2.3