From c93d3e84a48cdfe5cf397b2fbd2e215014c5777d Mon Sep 17 00:00:00 2001 From: mattab Date: Mon, 15 Dec 2014 20:25:22 +1300 Subject: Fixes #6529 Throw an exception when codebase is older than schema to prevent broken race conditions --- core/Updater.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'core/Updater.php') 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. * -- cgit v1.2.3