diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-01-12 02:39:41 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-01-12 02:39:41 +0300 |
commit | 636d5400a7aee9fff5b3966b06c5d4e248ce825c (patch) | |
tree | 5b4ba382285c344fd5d2b947906a878dc722cca5 /plugins/CorePluginsAdmin | |
parent | c144a0dd58d8cd47b09b477bb9bc82b1e9cd77f9 (diff) |
#6915 Renamed plugin management commands
Diffstat (limited to 'plugins/CorePluginsAdmin')
-rw-r--r-- | plugins/CorePluginsAdmin/Commands/ActivatePlugin.php | 44 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Commands/DeactivatePlugin.php | 44 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Commands/ListPlugins.php | 54 |
3 files changed, 142 insertions, 0 deletions
diff --git a/plugins/CorePluginsAdmin/Commands/ActivatePlugin.php b/plugins/CorePluginsAdmin/Commands/ActivatePlugin.php new file mode 100644 index 0000000000..7ef3c9bbeb --- /dev/null +++ b/plugins/CorePluginsAdmin/Commands/ActivatePlugin.php @@ -0,0 +1,44 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CorePluginsAdmin\Commands; + +use Piwik\Plugin\ConsoleCommand; +use Piwik\Plugin\Manager; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * plugin:activate console command. + */ +class ActivatePlugin extends ConsoleCommand +{ + protected function configure() + { + $this->setName('plugin:activate'); + $this->setDescription('Activate a plugin.'); + $this->addArgument('plugin', InputArgument::REQUIRED, 'The plugin name.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $pluginManager = Manager::getInstance(); + + $plugin = $input->getArgument('plugin'); + + if ($pluginManager->isPluginActivated($plugin)) { + $output->writeln('<comment>The plugin is already activated.</comment>'); + return; + } + + $pluginManager->activatePlugin($plugin); + + $output->writeln("Activated plugin <info>$plugin</info>"); + } +} diff --git a/plugins/CorePluginsAdmin/Commands/DeactivatePlugin.php b/plugins/CorePluginsAdmin/Commands/DeactivatePlugin.php new file mode 100644 index 0000000000..33f5671e48 --- /dev/null +++ b/plugins/CorePluginsAdmin/Commands/DeactivatePlugin.php @@ -0,0 +1,44 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CorePluginsAdmin\Commands; + +use Piwik\Plugin\ConsoleCommand; +use Piwik\Plugin\Manager; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * plugin:deactivate console command. + */ +class DeactivatePlugin extends ConsoleCommand +{ + protected function configure() + { + $this->setName('plugin:deactivate'); + $this->setDescription('Deactivate a plugin.'); + $this->addArgument('plugin', InputArgument::REQUIRED, 'The plugin name.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $pluginManager = Manager::getInstance(); + + $plugin = $input->getArgument('plugin'); + + if (!$pluginManager->isPluginActivated($plugin)) { + $output->writeln('<comment>The plugin is already deactivated.</comment>'); + return; + } + + $pluginManager->deactivatePlugin($plugin); + + $output->writeln("Deactivated plugin <info>$plugin</info>"); + } +} diff --git a/plugins/CorePluginsAdmin/Commands/ListPlugins.php b/plugins/CorePluginsAdmin/Commands/ListPlugins.php new file mode 100644 index 0000000000..0fc132e589 --- /dev/null +++ b/plugins/CorePluginsAdmin/Commands/ListPlugins.php @@ -0,0 +1,54 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CorePluginsAdmin\Commands; + +use Piwik\Plugin\ConsoleCommand; +use Piwik\Plugin\Manager; +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * plugin:list console command. + */ +class ListPlugins extends ConsoleCommand +{ + protected function configure() + { + $this->setName('plugin:list'); + $this->setDescription('List installed plugins.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $pluginManager = Manager::getInstance(); + + $plugins = $pluginManager->getInstalledPluginsName(); + + $plugins = array_map(function ($plugin) use ($pluginManager) { + return array( + '<info>' . $plugin . '</info>', + $pluginManager->isPluginBundledWithCore($plugin) ? 'Core' : 'Optional', + $pluginManager->isPluginActivated($plugin) ? 'Activated' : '<comment>Not activated</comment>', + ); + }, $plugins); + + // Sort Core plugins first + usort($plugins, function ($a, $b) { + return strcmp($a[1], $b[1]); + }); + + $table = new Table($output); + $table + ->setHeaders(array('Plugin', 'Core or optional?', 'Status')) + ->setRows($plugins) + ; + $table->render(); + } +} |