diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-12-15 10:25:22 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-12-15 10:25:22 +0300 |
commit | c93d3e84a48cdfe5cf397b2fbd2e215014c5777d (patch) | |
tree | c6315bec3cb1bd47e7dd1c53cc1e3ee1158a6d3d | |
parent | 12d4618aebf7d0658e28fef3d50c6ba2d5fb449e (diff) |
Fixes #6529 Throw an exception when codebase is older than schema to prevent broken race conditions
-rw-r--r-- | core/Exception/DatabaseSchemaIsNewerThanCodebaseException.php | 14 | ||||
-rw-r--r-- | core/FrontController.php | 2 | ||||
-rw-r--r-- | core/Updater.php | 21 | ||||
-rw-r--r-- | lang/en.json | 3 |
4 files changed, 40 insertions, 0 deletions
diff --git a/core/Exception/DatabaseSchemaIsNewerThanCodebaseException.php b/core/Exception/DatabaseSchemaIsNewerThanCodebaseException.php new file mode 100644 index 0000000000..accc4ce5d5 --- /dev/null +++ b/core/Exception/DatabaseSchemaIsNewerThanCodebaseException.php @@ -0,0 +1,14 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Exception; + +class DatabaseSchemaIsNewerThanCodebaseException extends Exception +{ + +}
\ No newline at end of file diff --git a/core/FrontController.php b/core/FrontController.php index 7d1702315f..dbaf75e22c 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -399,6 +399,8 @@ class FrontController extends Singleton */ Piwik::postEvent('Request.dispatchCoreAndPluginUpdatesScreen'); + Updater::throwIfPiwikVersionIsOlderThanDBSchema(); + \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins(); // ensure the current Piwik URL is known for later use diff --git a/core/Updater.php b/core/Updater.php index 692034d5e9..c9872d3481 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -8,6 +8,7 @@ */ namespace Piwik; use Piwik\Columns\Updater as ColumnUpdater; +use Piwik\Exception\DatabaseSchemaIsNewerThanCodebaseException; /** * Load and execute all relevant, incremental update scripts for Piwik core and plugins, and bump the component version numbers for completed updates. @@ -95,6 +96,26 @@ class Updater return 'version_' . $name; } + + /** + * This method ensures that Piwik Platform cannot be running when using a NEWER database + */ + public static function throwIfPiwikVersionIsOlderThanDBSchema() + { + $dbSchemaVersion = self::getCurrentRecordedComponentVersion('core'); + $current = Version::VERSION; + if(-1 === version_compare($current, $dbSchemaVersion)) { + $messages = array( + Piwik::translate('General_ExceptionDatabaseVersionNewerThanCodebase', array($current, $dbSchemaVersion)), + Piwik::translate('General_ExceptionDatabaseVersionNewerThanCodebaseWait'), + // we cannot fill in the Super User emails as we are failing before Authentication was ready + Piwik::translate('General_ExceptionContactSupportGeneric', array('', '')) + ); + throw new DatabaseSchemaIsNewerThanCodebaseException(implode(" ", $messages)); + } + } + + /** * Returns a list of components (core | plugin) that need to run through the upgrade process. * diff --git a/lang/en.json b/lang/en.json index de10952b1b..b68df794c2 100644 --- a/lang/en.json +++ b/lang/en.json @@ -145,9 +145,12 @@ "ErrorRequest": "Oops\u2026 there was a problem during the request. Maybe the server had a temporary issue, or maybe you requested a report with too much data. Please try again. If this error occurs repeatedly please %scontact your Piwik administrator%s for assistance.", "EvolutionOverPeriod": "Evolution over the period", "EvolutionSummaryGeneric": "%1$s in %2$s compared to %3$s in %4$s. Evolution: %5$s", + "ExceptionContactSupportGeneric": "If you still have this issue please %scontact your Piwik administrator%s for assistance. ", "ExceptionCheckUserHasSuperUserAccessOrIsTheUser": "The user has to be either a Super User or the user '%s' itself.", "ExceptionConfigurationFileNotFound": "The configuration file {%s} has not been found or could not be read.", "ExceptionDatabaseVersion": "Your %1$s version is %2$s but Piwik requires at least %3$s.", + "ExceptionDatabaseVersionNewerThanCodebase": "Your Piwik codebase is running the old version %1$s and we have detected that your Piwik Database has already been upgraded to the newer version %2$s.", + "ExceptionDatabaseVersionNewerThanCodebaseWait": "Maybe your Piwik administrators are currently finishing the upgrade process. Please try again in a few minutes.", "ExceptionFileIntegrity": "Integrity check failed: %s", "ExceptionFilesizeMismatch": "File size mismatch: %1$s (expected length: %2$s, found: %3$s)", "ExceptionIncompatibleClientServerVersions": "Your %1$s client version is %2$s which is incompatible with server version %3$s.", |