Piwik\Plugins\CoreUpdater\Updater::updatePiwik PHP Метод

updatePiwik() публичный Метод

Update Piwik codebase by downloading and installing the latest version.
public updatePiwik ( boolean $https = true ) : string[]
$https boolean Whether to use HTTPS if supported of not. If false, will use HTTP.
Результат string[] Return an array of messages for the user.
    public function updatePiwik($https = true)
    {
        if (!$this->isNewVersionAvailable()) {
            throw new Exception($this->translator->translate('CoreUpdater_ExceptionAlreadyLatestVersion', Version::VERSION));
        }
        SettingsServer::setMaxExecutionTime(0);
        $newVersion = $this->getLatestVersion();
        $url = $this->getArchiveUrl($newVersion, $https);
        $messages = array();
        try {
            $archiveFile = $this->downloadArchive($newVersion, $url);
            $messages[] = $this->translator->translate('CoreUpdater_DownloadingUpdateFromX', $url);
            $extractedArchiveDirectory = $this->decompressArchive($archiveFile);
            $messages[] = $this->translator->translate('CoreUpdater_UnpackingTheUpdate');
            $this->verifyDecompressedArchive($extractedArchiveDirectory);
            $messages[] = $this->translator->translate('CoreUpdater_VerifyingUnpackedFiles');
            if (Marketplace::isMarketplaceEnabled()) {
                // we need to load the marketplace already here, otherwise it will use the new, updated file in Piwik 3
                // we also need to make sure to create a new instance here as otherwise we would change the "global"
                // environment, but we only want to change piwik version temporarily for this task here
                $environment = StaticContainer::getContainer()->make('Piwik\\Plugins\\Marketplace\\Environment');
                $environment->setPiwikVersion($newVersion);
                /** @var \Piwik\Plugins\Marketplace\Api\Client $marketplaceClient */
                $marketplaceClient = StaticContainer::getContainer()->make('Piwik\\Plugins\\Marketplace\\Api\\Client', array('environment' => $environment));
                require_once PIWIK_DOCUMENT_ROOT . '/plugins/CorePluginsAdmin/PluginInstaller.php';
                require_once PIWIK_DOCUMENT_ROOT . '/plugins/Marketplace/Api/Exception.php';
            }
            $this->installNewFiles($extractedArchiveDirectory);
            $messages[] = $this->translator->translate('CoreUpdater_InstallingTheLatestVersion');
        } catch (ArchiveDownloadException $e) {
            throw $e;
        } catch (Exception $e) {
            throw new UpdaterException($e, $messages);
        }
        try {
            if (Marketplace::isMarketplaceEnabled() && !empty($marketplaceClient)) {
                $messages[] = $this->translator->translate('CoreUpdater_CheckingForPluginUpdates');
                $pluginManager = PluginManager::getInstance();
                $pluginManager->loadAllPluginsAndGetTheirInfo();
                $loadedPlugins = $pluginManager->getLoadedPlugins();
                $marketplaceClient->clearAllCacheEntries();
                $pluginsWithUpdate = $marketplaceClient->checkUpdates($loadedPlugins);
                foreach ($pluginsWithUpdate as $pluginWithUpdate) {
                    $pluginName = $pluginWithUpdate['name'];
                    $messages[] = $this->translator->translate('CoreUpdater_UpdatingPluginXToVersionY', array($pluginName, $pluginWithUpdate['version']));
                    $pluginInstaller = new PluginInstaller($marketplaceClient);
                    $pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName);
                }
            }
        } catch (MarketplaceApi\Exception $e) {
            // there is a problem with the connection to the server, ignore for now
        } catch (Exception $e) {
            throw new UpdaterException($e, $messages);
        }
        try {
            $disabledPluginNames = $this->disableIncompatiblePlugins($newVersion);
            if (!empty($disabledPluginNames)) {
                $messages[] = $this->translator->translate('CoreUpdater_DisablingIncompatiblePlugins', implode(', ', $disabledPluginNames));
            }
        } catch (Exception $e) {
            throw new UpdaterException($e, $messages);
        }
        return $messages;
    }

Usage Example

Пример #1
0
 public function oneClickUpdate()
 {
     Piwik::checkUserHasSuperUserAccess();
     $view = new OneClickDone(Piwik::getCurrentUserTokenAuth());
     $useHttps = Common::getRequestVar('https', 1, 'int');
     try {
         $messages = $this->updater->updatePiwik($useHttps);
     } catch (ArchiveDownloadException $e) {
         $view->httpsFail = $useHttps;
         $view->error = $e->getMessage();
         $messages = $e->getUpdateLogMessages();
     } catch (UpdaterException $e) {
         $view->error = $e->getMessage();
         $messages = $e->getUpdateLogMessages();
     }
     $view->feedbackMessages = $messages;
     $this->addCustomLogoInfo($view);
     return $view->render();
 }