Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 62e3f7e

Browse files
authored
Fixes #1589: @executeInDrupalVm not respected during invokeCommand. (#1595)
* Fixes #1589: @executeInDrupalVm not respected during invokeCommand. * Making invokeCommand() trigger Command Events.
1 parent 5efdffa commit 62e3f7e

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

src/Robo/Application.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Acquia\Blt\Robo;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Application as ConsoleApplication;
9+
10+
/**
11+
* Class Application
12+
* @package Acquia\Blt\Robo
13+
*/
14+
class Application extends ConsoleApplication {
15+
16+
/**
17+
* @param \Symfony\Component\Console\Command\Command $command
18+
* @param \Symfony\Component\Console\Input\InputInterface $input
19+
* @param \Symfony\Component\Console\Output\OutputInterface $output
20+
*
21+
* @return int
22+
* The exit code.
23+
*/
24+
public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
25+
return $this->doRunCommand($command, $input, $output);
26+
}
27+
28+
}

src/Robo/Blt.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Robo\Config\Config;
2121
use Robo\Robo;
2222
use Robo\Runner as RoboRunner;
23-
use Symfony\Component\Console\Application;
2423
use Symfony\Component\Console\Input\InputInterface;
2524
use Symfony\Component\Console\Input\InputOption;
2625
use Symfony\Component\Console\Output\OutputInterface;
@@ -224,7 +223,8 @@ public function configureContainer($container) {
224223
* The exiting status code of the application
225224
*/
226225
public function run(InputInterface $input, OutputInterface $output) {
227-
$status_code = $this->runner->run($input, $output, NULL, $this->commands);
226+
$application = $this->getContainer()->get('application');
227+
$status_code = $this->runner->run($input, $output, $application, $this->commands);
228228

229229
return $status_code;
230230
}

src/Robo/BltTasks.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,17 @@ protected function invokeCommand($command_name, array $args = []) {
9393
return 0;
9494
}
9595

96-
/** @var \Robo\Application $application */
96+
/** @var \Acquia\Blt\Robo\Application $application */
9797
$application = $this->getContainer()->get('application');
9898
$command = $application->find($command_name);
99+
99100
$input = new ArrayInput($args);
100101
$prefix = str_repeat(">", $this->invokeDepth);
101102
$this->output->writeln("<comment>$prefix $command_name</comment>");
102-
$returnCode = $command->run($input, $this->output());
103+
$return_code = $application->runCommand($command, $input, $this->output());
103104
$this->invokeDepth--;
104105

105-
return $returnCode;
106+
return $return_code;
106107
}
107108

108109
/**

src/Robo/Hooks/CommandEventHook.php

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function executeInDrupalVm(ConsoleCommandEvent $event) {
3636
if (method_exists($command, 'getAnnotationData')) {
3737
/* @var \Consolidation\AnnotatedCommand\AnnotationData */
3838
$annotation_data = $event->getCommand()->getAnnotationData();
39+
$this->warnIfDrupalVmNotRunning();
3940
if ($annotation_data->has('executeInDrupalVm') && $this->shouldExecuteInDrupalVm()) {
4041
$event->disableCommand();
4142
$args = $this->getCliArgs();
@@ -95,4 +96,13 @@ protected function shouldExecuteInDrupalVm() {
9596
&& !$this->getInspector()->isVmCli();
9697
}
9798

99+
/**
100+
* Emits a warning if Drupal VM is initialized but not running.
101+
*/
102+
protected function warnIfDrupalVmNotRunning() {
103+
if ($this->getInspector()->isDrupalVmLocallyInitialized() && !$this->getInspector()->isDrupalVmBooted()) {
104+
$this->logger->warning("Drupal VM is locally initialized, but it not running.");
105+
}
106+
}
107+
98108
}

0 commit comments

Comments
 (0)