diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2020-04-16 21:24:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 21:24:54 +0300 |
commit | 934ad5ab3551e2d0994e4168e0b6503f3bde1cf4 (patch) | |
tree | 4c44c0db9fd96c97a4eae9e9f5ddeba950e90697 /plugins/CoreUpdater | |
parent | a65912672c8b78af6a0018b049ffbf6d3cb8688c (diff) |
One click update in two parts so new code is loaded for second. (#15770)
* One click update in two parts so new code is loaded for second.
* remove no longer needed code
Diffstat (limited to 'plugins/CoreUpdater')
-rw-r--r-- | plugins/CoreUpdater/Controller.php | 12 | ||||
-rw-r--r-- | plugins/CoreUpdater/Updater.php | 65 |
2 files changed, 51 insertions, 26 deletions
diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php index d7ebb79489..306a27ed23 100644 --- a/plugins/CoreUpdater/Controller.php +++ b/plugins/CoreUpdater/Controller.php @@ -12,6 +12,7 @@ use Exception; use Piwik\AssetManager; use Piwik\Common; use Piwik\Config; +use Piwik\DataTable\Renderer\Json; use Piwik\DbHelper; use Piwik\Filechecks; use Piwik\FileIntegrity; @@ -172,6 +173,17 @@ class Controller extends \Piwik\Plugin\Controller return $view->render(); } + public function oneClickUpdatePartTwo() + { + Piwik::checkUserHasSuperUserAccess(); + + Json::sendHeaderJSON(); + + $messages = $this->updater->oneClickUpdatePartTwo(); + + echo json_encode($messages); + } + public function oneClickResults() { Filesystem::deleteAllCacheOnUpdate(); diff --git a/plugins/CoreUpdater/Updater.php b/plugins/CoreUpdater/Updater.php index 7baee1d46a..d3f8f54e1c 100644 --- a/plugins/CoreUpdater/Updater.php +++ b/plugins/CoreUpdater/Updater.php @@ -23,6 +23,7 @@ use Piwik\Plugins\Marketplace\Marketplace; use Piwik\SettingsServer; use Piwik\Translation\Translator; use Piwik\Unzip; +use Piwik\Url; use Piwik\Version; class Updater @@ -114,21 +115,6 @@ class Updater $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'); @@ -138,9 +124,45 @@ class Updater throw new UpdaterException($e, $messages); } + $partTwoUrl = Url::getCurrentUrlWithoutQueryString() . Url::getCurrentQueryStringWithParametersModified([ + 'action' => 'oneClickUpdatePartTwo', + ]); + + $response = Http::sendHttpRequest($partTwoUrl, 300); + $response = @json_decode($response, $assoc = true); + + $messages = array_merge($messages, $response); + + 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; + } + + public function oneClickUpdatePartTwo() + { + $messages = []; + + $newVersion = Version::VERSION; + + // 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 + )); + try { - if (Marketplace::isMarketplaceEnabled() && !empty($marketplaceClient)) { + if (Marketplace::isMarketplaceEnabled()) { $messages[] = $this->translator->translate('CoreUpdater_CheckingForPluginUpdates'); $pluginManager = PluginManager::getInstance(); $pluginManager->loadAllPluginsAndGetTheirInfo(); @@ -152,7 +174,7 @@ class Updater foreach ($pluginsWithUpdate as $pluginWithUpdate) { $pluginName = $pluginWithUpdate['name']; $messages[] = $this->translator->translate('CoreUpdater_UpdatingPluginXToVersionY', - array($pluginName, $pluginWithUpdate['version'])); + array($pluginName, $pluginWithUpdate['version'])); $pluginInstaller = new PluginInstaller($marketplaceClient); $pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName); } @@ -163,15 +185,6 @@ class Updater 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; } |