Piwik\Updater::update PHP Method

update() public method

Update the named component
public update ( string $componentName ) : array
$componentName string 'core', or plugin name
return array of warning strings if applicable
    public function update($componentName)
    {
        $warningMessages = array();
        $this->executeListenerHook('onComponentUpdateStarting', array($componentName));
        foreach ($this->componentsWithUpdateFile[$componentName] as $file => $fileVersion) {
            try {
                require_once $file;
                // prefixed by PIWIK_INCLUDE_PATH
                $className = $this->getUpdateClassName($componentName, $fileVersion);
                if (!in_array($className, $this->updatedClasses) && class_exists($className, false)) {
                    $this->executeListenerHook('onComponentUpdateFileStarting', array($componentName, $file, $className, $fileVersion));
                    $this->executeSingleUpdateClass($className);
                    $this->executeListenerHook('onComponentUpdateFileFinished', array($componentName, $file, $className, $fileVersion));
                    // makes sure to call Piwik\Columns\Updater only once as one call updates all dimensions at the same
                    // time for better performance
                    $this->updatedClasses[] = $className;
                }
                $this->markComponentSuccessfullyUpdated($componentName, $fileVersion);
            } catch (UpdaterErrorException $e) {
                $this->executeListenerHook('onError', array($componentName, $fileVersion, $e));
                throw $e;
            } catch (\Exception $e) {
                $warningMessages[] = $e->getMessage();
                $this->executeListenerHook('onWarning', array($componentName, $fileVersion, $e));
            }
        }
        // to debug, create core/Updates/X.php, update the core/Version.php, throw an Exception in the try, and comment the following lines
        $updatedVersion = $this->componentsWithNewVersion[$componentName][self::INDEX_NEW_VERSION];
        $this->markComponentSuccessfullyUpdated($componentName, $updatedVersion);
        $this->executeListenerHook('onComponentUpdateFinished', array($componentName, $updatedVersion, $warningMessages));
        return $warningMessages;
    }

Usage Example

示例#1
0
 public static function updateComponents(Updater $updater, $componentsWithUpdateFile)
 {
     $warnings = array();
     $errors = array();
     $deactivatedPlugins = array();
     $coreError = false;
     if (!empty($componentsWithUpdateFile)) {
         $currentAccess = Access::getInstance();
         $hasSuperUserAccess = $currentAccess->hasSuperUserAccess();
         if (!$hasSuperUserAccess) {
             $currentAccess->setSuperUserAccess(true);
         }
         // if error in any core update, show message + help message + EXIT
         // if errors in any plugins updates, show them on screen, disable plugins that errored + CONTINUE
         // if warning in any core update or in any plugins update, show message + CONTINUE
         // if no error or warning, success message + CONTINUE
         foreach ($componentsWithUpdateFile as $name => $filenames) {
             try {
                 $warnings = array_merge($warnings, $updater->update($name));
             } catch (UpdaterErrorException $e) {
                 $errors[] = $e->getMessage();
                 if ($name == 'core') {
                     $coreError = true;
                     break;
                 } elseif (\Piwik\Plugin\Manager::getInstance()->isPluginActivated($name)) {
                     \Piwik\Plugin\Manager::getInstance()->deactivatePlugin($name);
                     $deactivatedPlugins[] = $name;
                 }
             }
         }
         if (!$hasSuperUserAccess) {
             $currentAccess->setSuperUserAccess(false);
         }
     }
     Filesystem::deleteAllCacheOnUpdate();
     $result = array('warnings' => $warnings, 'errors' => $errors, 'coreError' => $coreError, 'deactivatedPlugins' => $deactivatedPlugins);
     /**
      * Triggered after Piwik has been updated.
      */
     Piwik::postEvent('CoreUpdater.update.end');
     return $result;
 }