diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2010-03-18 19:27:32 +0300 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2010-03-18 19:27:32 +0300 |
commit | 59925362d527fbd051a4e12113abcab282983436 (patch) | |
tree | 277ec9f955163e02552b87dc359b500234914c1e /core/Updater.php | |
parent | 822aaed658125f9f7318ed4c81701e3426fde215 (diff) |
Fixes #1151
Clarifying update process for large piwik instances. outputs list of SQL queries that will be executed during updates.
Fixes language selector during update, which was only working after second refresh.
git-svn-id: http://dev.piwik.org/svn/trunk@1941 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/Updater.php')
-rw-r--r-- | core/Updater.php | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/core/Updater.php b/core/Updater.php index 37afc3f36c..b7402d85be 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -61,13 +61,23 @@ class Piwik_Updater public function recordComponentSuccessfullyUpdated($name, $version) { try { - Piwik_SetOption('version_'.$name, $version, $autoload = 1); + Piwik_SetOption($this->getNameInOptionTable($name), $version, $autoload = 1); } catch(Exception $e) { // case when the option table is not yet created (before 0.2.10) } } /** + * Returns the flag name to use in the option table to record current schema version + * @param string $name + * @return string + */ + private function getNameInOptionTable($name) + { + return 'version_'.$name; + } + + /** * Returns a list of components (core | plugin) that need to run through the upgrade process. * * @return array( componentName => array( file1 => version1, [...]), [...]) @@ -92,34 +102,66 @@ class Piwik_Updater } /** + * Returns the list of SQL queries that would be executed during the update + * + * @return array of SQL queries + */ + public function getSqlQueriesToExecute() + { + $queries = array(); + foreach($this->componentsWithUpdateFile as $componentName => $componentUpdateInfo) + { + foreach($componentUpdateInfo as $file => $fileVersion) + { + require_once $file; // prefixed by PIWIK_INCLUDE_PATH + + $className = $this->getUpdateClassName($componentName, $fileVersion); + if(class_exists($className, false)) + { + $queriesForComponent = call_user_func( array($className, 'getSql')); + foreach($queriesForComponent as $query => $error) { + $queries[] = $query.';'; + } + } + } + // unfortunately had to extract this query from the Piwik_Option class + $queries[] = 'UPDATE '.Piwik::prefixTable('option').' + SET option_value = "' .$fileVersion.'" + WHERE option_name = "'. $this->getNameInOptionTable($componentName).'";'; + } + return $queries; + } + + private function getUpdateClassName($componentName, $fileVersion) + { + if($componentName == 'core') + { + return 'Piwik_Updates_' . str_replace('.', '_', $fileVersion); + } + return 'Piwik_'. $componentName .'_Updates_' . str_replace('.', '_', $fileVersion); + } + + /** * Update the named component * - * @param string $name + * @param string $componentName 'core', or plugin name * @return array of warning strings if applicable */ - public function update($name) + public function update($componentName) { $warningMessages = array(); - foreach($this->componentsWithUpdateFile[$name] as $file => $fileVersion) + foreach($this->componentsWithUpdateFile[$componentName] as $file => $fileVersion) { try { require_once $file; // prefixed by PIWIK_INCLUDE_PATH - if($name == 'core') - { - $className = 'Piwik_Updates_' . str_replace('.', '_', $fileVersion); - } - else - { - $className = 'Piwik_'. $name .'_Updates_' . str_replace('.', '_', $fileVersion); - } - + $className = $this->getUpdateClassName($componentName, $fileVersion); if(class_exists($className, false)) { call_user_func( array($className, 'update') ); } - $this->recordComponentSuccessfullyUpdated($name, $fileVersion); + $this->recordComponentSuccessfullyUpdated($componentName, $fileVersion); } catch( Piwik_Updater_UpdateErrorException $e) { throw $e; } catch( Exception $e) { @@ -128,7 +170,7 @@ class Piwik_Updater } // to debug, create core/Updates/X.php, update the core/Version.php, throw an Exception in the try, and comment the following line - $this->recordComponentSuccessfullyUpdated($name, $this->componentsWithNewVersion[$name][self::INDEX_NEW_VERSION]); + $this->recordComponentSuccessfullyUpdated($componentName, $this->componentsWithNewVersion[$componentName][self::INDEX_NEW_VERSION]); return $warningMessages; } |