Skip to content

Commit

Permalink
Fixes acquia#1440: Cannot disable security-updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed May 4, 2017
1 parent 7416a46 commit ccae73c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
40 changes: 40 additions & 0 deletions src/Robo/BltTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ protected function invokeCommands(array $commands) {
* The exit code of the command.
*/
protected function invokeCommand($command_name, array $args = []) {

// 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 @@ -88,6 +94,40 @@ protected function invokeCommand($command_name, array $args = []) {
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;
}

/**
* Invokes a given 'target-hooks' hook, typically defined in project.yml.
*
Expand Down
15 changes: 4 additions & 11 deletions src/Robo/Hooks/CommandEventHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Acquia\Blt\Robo\Hooks;

use Acquia\Blt\Robo\Common\ArrayManipulator;
use Acquia\Blt\Robo\BltTasks;
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
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;

/**
Expand All @@ -17,7 +16,7 @@
* 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 {
class CommandEventHook extends BltTasks implements IOAwareInterface, ConfigAwareInterface, LoggerAwareInterface {

use ConfigAwareTrait;
use LoggerAwareTrait;
Expand All @@ -29,14 +28,8 @@ class CommandEventHook extends Tasks implements IOAwareInterface, ConfigAwareInt
*/
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 (!empty($disabled_commands[$command->getName()]) && $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();
}
}

}

0 comments on commit ccae73c

Please sign in to comment.