installOrUpdatePluginFromMarketplace() public method

public installOrUpdatePluginFromMarketplace ( $pluginName )
示例#1
0
 private function createUpdateOrInstallView($template, $nonceName)
 {
     static::dieIfMarketplaceIsDisabled();
     $pluginName = $this->initPluginModification($nonceName);
     $this->dieIfPluginsAdminIsDisabled();
     $view = $this->configureView('@CorePluginsAdmin/' . $template);
     $view->plugin = array('name' => $pluginName);
     try {
         $pluginInstaller = new PluginInstaller($pluginName);
         $pluginInstaller->installOrUpdatePluginFromMarketplace();
     } catch (\Exception $e) {
         $notification = new Notification($e->getMessage());
         $notification->context = Notification::CONTEXT_ERROR;
         Notification\Manager::notify('CorePluginsAdmin_InstallPlugin', $notification);
         $this->redirectAfterModification(true);
         return;
     }
     $marketplace = new Marketplace();
     $view->plugin = $marketplace->getPluginInfo($pluginName);
     return $view;
 }
示例#2
0
 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;
 }
示例#3
0
文件: Updater.php 项目: piwik/piwik
 /**
  * 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;
 }