Skip to content
Extraits de code Groupes Projets
Valider b5ad8fe1 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Merge new ActivatePlugin/DeactivatePlugin commands to one ManagePlugin command.

parent 4e9fc594
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CoreConsole\Commands;
use Piwik\Plugin\Manager;
use Piwik\Plugin\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @package CloudAdmin
*/
class DeactivatePlugin extends ConsoleCommand
{
protected function configure()
{
$this->setName('plugin:deactivate');
$this->setDescription("Deactivate a plugin.");
$this->addArgument("plugins", InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Plugin name(s) to deactivate.');
$this->addOption('domain', null, InputOption::VALUE_REQUIRED, "The domain to deactivate the plugin for.");
}
/**
* Execute command like: ./console cloudadmin:plugin activate CustomAlerts --piwik-domain=testcustomer.piwik.pro
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$plugins = $input->getArgument('plugins');
foreach ($plugins as $plugin) {
Manager::getInstance()->deactivatePlugin($plugin);
$output->writeln("Activating plugin <info>$plugin</info>");
}
}
}
\ No newline at end of file
...@@ -18,14 +18,20 @@ use Symfony\Component\Console\Output\OutputInterface; ...@@ -18,14 +18,20 @@ use Symfony\Component\Console\Output\OutputInterface;
/** /**
* @package CloudAdmin * @package CloudAdmin
*/ */
class ActivatePlugin extends ConsoleCommand class ManagePlugin extends ConsoleCommand
{ {
private $operations = array();
protected function configure() protected function configure()
{ {
$this->setName('plugin:activate'); $this->setName('core:plugin');
$this->setDescription("Activate a plugin."); $this->setDescription("Perform various actions regarding one or more plugins.");
$this->addArgument("operation", InputArgument::REQUIRED, "Operation to apply (can be 'activate' or 'deactivate').");
$this->addArgument("plugins", InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Plugin name(s) to activate.'); $this->addArgument("plugins", InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Plugin name(s) to activate.');
$this->addOption('domain', null, InputOption::VALUE_REQUIRED, "The domain to activate the plugin for."); $this->addOption('domain', null, InputOption::VALUE_REQUIRED, "The domain to activate the plugin for.");
$this->operations['activate'] = 'activatePlugin';
$this->operations['deactivate'] = 'deactivatePlugin';
} }
/** /**
...@@ -33,11 +39,30 @@ class ActivatePlugin extends ConsoleCommand ...@@ -33,11 +39,30 @@ class ActivatePlugin extends ConsoleCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$operation = $input->getArgument("operation");
$plugins = $input->getArgument('plugins'); $plugins = $input->getArgument('plugins');
foreach ($plugins as $plugin) {
Manager::getInstance()->activatePlugin($plugin);
$output->writeln("Activating plugin <info>$plugin</info>"); if (empty($this->operations[$operation])) {
throw new Exception("Invalid operation '$operation'.");
} }
$fn = $this->operations[$operation];
foreach ($plugins as $plugin) {
call_user_func(array($this, $fn), $input, $output, $plugin);
}
}
private function activatePlugin(InputInterface $input, OutputInterface $output, $plugin)
{
Manager::getInstance()->activatePlugin($plugin, $input, $output);
$output->writeln("Activated plugin <info>$plugin</info>");
}
private function deactivatePlugin(InputInterface $input, OutputInterface $output, $plugin)
{
Manager::getInstance()->deactivatePlugin($plugin, $input, $output);
$output->writeln("Deactivated plugin <info>$plugin</info>");
} }
} }
\ No newline at end of file
...@@ -39,7 +39,6 @@ class CoreConsole extends \Piwik\Plugin ...@@ -39,7 +39,6 @@ class CoreConsole extends \Piwik\Plugin
$commands[] = 'Piwik\Plugins\CoreConsole\Commands\GenerateTest'; $commands[] = 'Piwik\Plugins\CoreConsole\Commands\GenerateTest';
$commands[] = 'Piwik\Plugins\CoreConsole\Commands\GenerateCommand'; $commands[] = 'Piwik\Plugins\CoreConsole\Commands\GenerateCommand';
$commands[] = 'Piwik\Plugins\CoreConsole\Commands\SyncUITestScreenshots'; $commands[] = 'Piwik\Plugins\CoreConsole\Commands\SyncUITestScreenshots';
$commands[] = 'Piwik\Plugins\CoreConsole\Commands\ActivatePlugin'; $commands[] = 'Piwik\Plugins\CoreConsole\Commands\ManagePlugin';
$commands[] = 'Piwik\Plugins\CoreConsole\Commands\DeactivatePlugin';
} }
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter