Piwik\Updater::updateComponents PHP Method

updateComponents() public method

Updates multiple components, while capturing & returning errors and warnings.
public updateComponents ( string[] $componentsWithUpdateFile ) : array
$componentsWithUpdateFile string[] Component names mapped with arrays of update files. Same structure as the result of `getComponentsWithUpdateFile()`.
return array Information about the update process, including: * **warnings**: The list of warnings that occurred during the update process. * **errors**: The list of updater exceptions thrown during individual component updates. * **coreError**: True if an exception was thrown while updating core. * **deactivatedPlugins**: The list of plugins that were deactivated due to an error in the update process.
    public function updateComponents($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, $this->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;
    }

Usage Example

示例#1
0
 private function doExecuteUpdates($view, DbUpdater $updater, $componentsWithUpdateFile)
 {
     $result = $updater->updateComponents($componentsWithUpdateFile);
     $this->coreError = $result['coreError'];
     $this->warningMessages = $result['warnings'];
     $this->errorMessages = $result['errors'];
     $this->deactivatedPlugins = $result['deactivatedPlugins'];
     $view->coreError = $this->coreError;
     $view->warningMessages = $this->warningMessages;
     $view->errorMessages = $this->errorMessages;
     $view->deactivatedPlugins = $this->deactivatedPlugins;
 }
All Usage Examples Of Piwik\Updater::updateComponents