Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1440: Cannot disable security-updates. #1489

Merged
merged 1 commit into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Robo/BltTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public function invokeCommands(array $commands) {
* The exit code of the command.
*/
public function invokeCommand($command_name) {

// Skip invocation of disabled commands.
if ($this->isCommandDisabled($command_name)) {
return 0;
}

/** @var \Robo\Application $application */
$application = $this->getContainer()->get('application');
$command = $application->find($command_name);
Expand All @@ -79,6 +85,37 @@ public function invokeCommand($command_name) {
return $returnCode;
}

/**
* Gets an array of commands that have been configured to be disabled.
*
* @return array
* A flat array of disabled commands.
*/
protected function getDisabledCommands() {
$disabled_commands_config = $this->getConfigValue('disable-targets');
if ($disabled_commands_config) {
$disabled_commands = ArrayManipulator::flattenMultidimensionalArray($disabled_commands_config, ':');
return $disabled_commands;
}
return [];
}
/**
* Determines if a command has been disabled via disable-targets.
*
* @param string $command
* The command name.
*
* @return bool
* TRUE if the command is disabled.
*/
protected function isCommandDisabled($command) {
$disabled_commands = $this->getDisabledCommands();
if (is_array($disabled_commands) && array_key_exists($command, $disabled_commands) && $disabled_commands[$command]) {
$this->output()->writeln("The $command command is disabled.");
return TRUE;
}
return FALSE;
}

/**
* @param $array
Expand Down
23 changes: 5 additions & 18 deletions src/Robo/Hooks/CommandEventHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,32 @@

namespace Acquia\Blt\Robo\Hooks;

use Acquia\Blt\Robo\Common\ArrayManipulator;
use Acquia\Blt\Robo\Common\IO;
use Acquia\Blt\Robo\BltTasks;
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Acquia\Blt\Robo\Console\ConfigInput;
use Consolidation\AnnotatedCommand\AnnotationData;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Robo\Contract\IOAwareInterface;
use Robo\Tasks;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* This class defines hooks that provide user interaction.
*
* These hooks typically use a Wizard to evaluate the validity of config or
* state and guide the user toward resolving issues.
*/
class CommandEventHook extends Tasks implements IOAwareInterface, ConfigAwareInterface, LoggerAwareInterface {

use ConfigAwareTrait;
use LoggerAwareTrait;

class CommandEventHook extends BltTasks {

/**
* Disable any command listed in the `disable-target` config key.
*
* @hook command-event *
*/
public function skipDisabledCommands(ConsoleCommandEvent $event) {
$command = $event->getCommand();
$disabled_commands_config = $this->getConfigValue('disable-targets');
if ($disabled_commands_config) {
$disabled_commands = ArrayManipulator::flattenMultidimensionalArray($disabled_commands_config, ':');
if (in_array($command->getName(), $disabled_commands) && $disabled_commands[$command->getName()]) {
$event->disableCommand();
$this->output()->writeln("The {$command->getName()} command has been disabled. Skipping execution.");
}
if ($this->isCommandDisabled($command->getName())) {
$event->disableCommand();
}
}

Expand Down