public function uploadPlugin() { static::dieIfPluginsAdminIsDisabled(); Piwik::checkUserHasSuperUserAccess(); $nonce = Common::getRequestVar('nonce', null, 'string'); if (!Nonce::verifyNonce(MarketplaceController::INSTALL_NONCE, $nonce)) { throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch')); } Nonce::discardNonce(MarketplaceController::INSTALL_NONCE); if (empty($_FILES['pluginZip'])) { throw new \Exception('You did not specify a ZIP file.'); } if (!empty($_FILES['pluginZip']['error'])) { throw new \Exception('Something went wrong during the plugin file upload. Please try again.'); } $file = $_FILES['pluginZip']['tmp_name']; if (!file_exists($file)) { throw new \Exception('Something went wrong during the plugin file upload. Please try again.'); } $view = $this->configureView('@CorePluginsAdmin/uploadPlugin'); $pluginMetadata = $this->pluginInstaller->installOrUpdatePluginFromFile($file); $view->nonce = Nonce::getNonce(static::ACTIVATE_NONCE); $view->plugin = array('name' => $pluginMetadata->name, 'version' => $pluginMetadata->version, 'isTheme' => !empty($pluginMetadata->theme), 'isActivated' => $this->pluginManager->isPluginActivated($pluginMetadata->name)); return $view->render(); }
private function createUpdateOrInstallView($template, $nonceName) { Piwik::checkUserHasSuperUserAccess(); $this->dieIfPluginsAdminIsDisabled(); $this->displayWarningIfConfigFileNotWritable(); $pluginName = $this->getPluginNameIfNonceValid($nonceName); $view = new View('@Marketplace/' . $template); $this->setBasicVariablesView($view); $view->errorMessage = ''; $view->plugin = array('name' => $pluginName); try { $this->pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName); } catch (\Exception $e) { $notification = new Notification($e->getMessage()); $notification->context = Notification::CONTEXT_ERROR; $notification->type = Notification::TYPE_PERSISTENT; $notification->flags = Notification::FLAG_CLEAR; Notification\Manager::notify('CorePluginsAdmin_InstallPlugin', $notification); Url::redirectToReferrer(); return; } $view->plugin = $this->plugins->getPluginInfo($pluginName); return $view; }
/** * Update Piwik codebase by downloading and installing the latest version. * * @param bool $https Whether to use HTTPS if supported of not. If false, will use HTTP. * @return string[] Return an array of messages for the user. * @throws ArchiveDownloadException * @throws UpdaterException * @throws Exception */ 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; }