Skip to content

Commit

Permalink
Fixes #6529 Throw an exception when codebase is older than schema to …
Browse files Browse the repository at this point in the history
…prevent broken race conditions
  • Loading branch information
mattab committed Dec 15, 2014
1 parent 12d4618 commit c93d3e8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 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
{

}
2 changes: 2 additions & 0 deletions core/FrontController.php
Expand Up @@ -399,6 +399,8 @@ public function init()
*/
Piwik::postEvent('Request.dispatchCoreAndPluginUpdatesScreen');

Updater::throwIfPiwikVersionIsOlderThanDBSchema();

\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();

// ensure the current Piwik URL is known for later use
Expand Down
21 changes: 21 additions & 0 deletions core/Updater.php
Expand Up @@ -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.
Expand Down Expand Up @@ -95,6 +96,26 @@ private static function getNameInOptionTable($name)
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.
*
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Expand Up @@ -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.",
Expand Down

7 comments on commit c93d3e8

@mattab
Copy link
Member Author

@mattab mattab commented on c93d3e8 Dec 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for #6829

@saleemkce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mattab This error is always irritating, "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 Maybe your Piwik administrators are currently finishing the upgrade process. Please try again in a few minutes." because even after one hour, this error does not go away and it seems that the developer is struck with the index page and could not do anything. It would be great if the given codebase version and database version always stay in sync because in that case developer is free to access local piwik site until new (codebase + database) version update is available. I have noticed this error several times. Maybe, we need more sensible and accurate update reporting.

@mattab
Copy link
Member Author

@mattab mattab commented on c93d3e8 Apr 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, we need more sensible and accurate update reporting.

this error is only displayed when Piwik runs on an oldcodebase. make sure you update your codebase to run the latest Piwik on all servers

@diosmosis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this also occurs when switching branches, going to old Piwik versions to test, etc. Perhaps it can be disabled when Development mode is enabled?

@mattab
Copy link
Member Author

@mattab mattab commented on c93d3e8 Apr 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it can be disabled when Development mode is enabled?

Why not, feel free to create issue or PR

@saleemkce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diosmosis I too talk about exactly the same thing. As Matthieu suggests, we need to create an issue/PR so that this doesn't occur in development when we actively switch branches here and there.

@mattab
Copy link
Member Author

@mattab mattab commented on c93d3e8 Apr 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saleemkce actually it was done few days ago: 9037275

so this should be fixed now in git master!

Please sign in to comment.