public function test_deactivatePlugin() { $this->assertFalse($this->manager->isPluginActivated('ExampleTheme')); $this->manager->activatePlugin('ExampleTheme'); $this->assertTrue($this->manager->isPluginActivated('ExampleTheme')); $this->manager->deactivatePlugin('ExampleTheme'); $this->assertFalse($this->manager->isPluginActivated('ExampleTheme')); }
public function activate($redirectAfter = true) { $pluginName = $this->initPluginModification(static::ACTIVATE_NONCE); $this->dieIfPluginsAdminIsDisabled(); $this->pluginManager->activatePlugin($pluginName); if ($redirectAfter) { $message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName)); if ($this->settingsProvider->getSystemSettings($pluginName)) { $target = sprintf('<a href="index.php%s#%s">', Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')), $pluginName); $message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>')); } $notification = new Notification($message); $notification->raw = true; $notification->title = $this->translator->translate('General_WellDone'); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification); $redirectTo = Common::getRequestVar('redirectTo', '', 'string'); if (!empty($redirectTo) && $redirectTo === 'marketplace') { $this->redirectToIndex('Marketplace', 'overview'); } elseif (!empty($redirectTo) && $redirectTo === 'referrer') { $this->redirectAfterModification($redirectAfter); } else { $plugin = $this->pluginManager->loadPlugin($pluginName); $actionToRedirect = 'plugins'; if ($plugin->isTheme()) { $actionToRedirect = 'themes'; } $this->redirectToIndex('CorePluginsAdmin', $actionToRedirect); } } }
public function installAllPaidPlugins() { Piwik::checkUserHasSuperUserAccess(); $this->dieIfPluginsAdminIsDisabled(); Plugin\ControllerAdmin::displayWarningIfConfigFileNotWritable(); Nonce::checkNonce(static::INSTALL_NONCE); $paidPlugins = $this->plugins->getAllPaidPlugins(); $hasErrors = false; foreach ($paidPlugins as $paidPlugin) { if (!$this->canPluginBeInstalled($paidPlugin)) { continue; } $pluginName = $paidPlugin['name']; try { $this->pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName); } catch (\Exception $e) { $notification = new Notification($e->getMessage()); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('Marketplace_Install' . $pluginName, $notification); $hasErrors = true; } } if ($hasErrors) { Url::redirectToReferrer(); return; } $dependency = new Plugin\Dependency(); for ($i = 0; $i <= 10; $i++) { foreach ($paidPlugins as $index => $paidPlugin) { $pluginName = $paidPlugin['name']; if ($this->pluginManager->isPluginActivated($pluginName)) { unset($paidPlugins[$index]); continue; } if (empty($paidPlugin['require']) || !$dependency->hasDependencyToDisabledPlugin($paidPlugin['require'])) { unset($paidPlugins[$index]); try { $this->pluginManager->activatePlugin($pluginName); } catch (Exception $e) { $hasErrors = true; $notification = new Notification($e->getMessage()); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('Marketplace_Install' . $pluginName, $notification); } } } } if ($hasErrors) { $notification = new Notification(Piwik::translate('Marketplace_OnlySomePaidPluginsInstalledAndActivated')); $notification->context = Notification::CONTEXT_INFO; } else { $notification = new Notification(Piwik::translate('Marketplace_AllPaidPluginsInstalledAndActivated')); $notification->context = Notification::CONTEXT_SUCCESS; } Notification\Manager::notify('Marketplace_InstallAll', $notification); Url::redirectToReferrer(); }
public function exec() { if (!$this->pluginManager->isPluginActivated($this->pluginName)) { $this->pluginManager->activatePlugin($this->pluginName); } }