Skip to content

Commit ccae73c

Browse files
committed
Fixes acquia#1440: Cannot disable security-updates.
1 parent 7416a46 commit ccae73c

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

src/Robo/BltTasks.php

+40
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ protected function invokeCommands(array $commands) {
7777
* The exit code of the command.
7878
*/
7979
protected function invokeCommand($command_name, array $args = []) {
80+
81+
// Skip invocation of disabled commands.
82+
if ($this->isCommandDisabled($command_name)) {
83+
return 0;
84+
}
85+
8086
/** @var \Robo\Application $application */
8187
$application = $this->getContainer()->get('application');
8288
$command = $application->find($command_name);
@@ -88,6 +94,40 @@ protected function invokeCommand($command_name, array $args = []) {
8894
return $returnCode;
8995
}
9096

97+
/**
98+
* Gets an array of commands that have been configured to be disabled.
99+
*
100+
* @return array
101+
* A flat array of disabled commands.
102+
*/
103+
protected function getDisabledCommands() {
104+
$disabled_commands_config = $this->getConfigValue('disable-targets');
105+
if ($disabled_commands_config) {
106+
$disabled_commands = ArrayManipulator::flattenMultidimensionalArray($disabled_commands_config, ':');
107+
return $disabled_commands;
108+
}
109+
return [];
110+
}
111+
112+
/**
113+
* Determines if a command has been disabled via disable-targets.
114+
*
115+
* @param string $command
116+
* The command name.
117+
*
118+
* @return bool
119+
* TRUE if the command is disabled.
120+
*/
121+
protected function isCommandDisabled($command) {
122+
$disabled_commands = $this->getDisabledCommands();
123+
if (is_array($disabled_commands) && array_key_exists($command, $disabled_commands) && $disabled_commands[$command]) {
124+
$this->output()->writeln("The $command command is disabled.");
125+
return TRUE;
126+
}
127+
128+
return FALSE;
129+
}
130+
91131
/**
92132
* Invokes a given 'target-hooks' hook, typically defined in project.yml.
93133
*

src/Robo/Hooks/CommandEventHook.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Acquia\Blt\Robo\Hooks;
44

5-
use Acquia\Blt\Robo\Common\ArrayManipulator;
5+
use Acquia\Blt\Robo\BltTasks;
66
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
77
use Psr\Log\LoggerAwareInterface;
88
use Psr\Log\LoggerAwareTrait;
99
use Robo\Contract\ConfigAwareInterface;
1010
use Robo\Contract\IOAwareInterface;
11-
use Robo\Tasks;
1211
use Symfony\Component\Console\Event\ConsoleCommandEvent;
1312

1413
/**
@@ -17,7 +16,7 @@
1716
* These hooks typically use a Wizard to evaluate the validity of config or
1817
* state and guide the user toward resolving issues.
1918
*/
20-
class CommandEventHook extends Tasks implements IOAwareInterface, ConfigAwareInterface, LoggerAwareInterface {
19+
class CommandEventHook extends BltTasks implements IOAwareInterface, ConfigAwareInterface, LoggerAwareInterface {
2120

2221
use ConfigAwareTrait;
2322
use LoggerAwareTrait;
@@ -29,14 +28,8 @@ class CommandEventHook extends Tasks implements IOAwareInterface, ConfigAwareInt
2928
*/
3029
public function skipDisabledCommands(ConsoleCommandEvent $event) {
3130
$command = $event->getCommand();
32-
$disabled_commands_config = $this->getConfigValue('disable-targets');
33-
if ($disabled_commands_config) {
34-
$disabled_commands = ArrayManipulator::flattenMultidimensionalArray($disabled_commands_config, ':');
35-
if (!empty($disabled_commands[$command->getName()]) && $disabled_commands[$command->getName()]) {
36-
$event->disableCommand();
37-
$this->output()->writeln("The {$command->getName()} command has been disabled. Skipping execution.");
38-
}
31+
if ($this->isCommandDisabled($command->getName())) {
32+
$event->disableCommand();
3933
}
4034
}
41-
4235
}

0 commit comments

Comments
 (0)