forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoctorCommand.php
84 lines (70 loc) · 2.53 KB
/
DoctorCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Acquia\Blt\Robo\Commands\Blt;
use Acquia\Blt\Robo\BltTasks;
use Symfony\Component\Yaml\Yaml;
/**
* Defines commands in the "blt:doctor" namespace.
*/
class DoctorCommand extends BltTasks {
/**
* Inspects your local blt configuration for possible issues.
*
* @command doctor
*/
public function doctor() {
// Attempt to run BLT doctor inside of a VM.
if ($this->getInspector()->isDrupalVmLocallyInitialized()
&& $this->getInspector()->isDrupalVmBooted()
&& !$this->getInspector()->isVmCli()) {
$result = $this->executeDoctorInsideVm();
if ($result->wasSuccessful()) {
return $result->getExitCode();
}
}
// Try BLT doctor with default alias. This might be a Drupal VM alias.
$alias = $this->getConfigValue('drush.alias');
$this->say('Attempting to run doctor on host machine...');
$result = $this->executeDoctorOnHost($alias);
// If default alias failed, try again using @self alias.
if (!$result->wasSuccessful() && $alias != 'self') {
$this->logger->warning("Unable to run the doctor using alias '@$alias'. Trying with '@self'...");
$this->executeDoctorOnHost('self');
}
// If @self fails, try without any alias.
if (!$result->wasSuccessful() && $alias != '') {
$this->logger->warning("Unable to run the doctor using alias '@self'. Trying without alias...");
$this->executeDoctorOnHost('');
}
return $result->getExitCode();
}
/**
* Executes `blt doctor` inside Drupal VM.
*
* @return \Robo\Result
* The command result.
*/
protected function executeDoctorInsideVm() {
$drupal_vm_config = Yaml::parse(file_get_contents($this->getConfigValue('repo.root') . '/box/config.yml'));
$repo_root = $drupal_vm_config['vagrant_synced_folders'][0]['destination'];
$this->say("Drupal VM was detected. Running blt doctor inside of VM...");
$command = "cd $repo_root && $repo_root/vendor/bin/drush cc drush && $repo_root/vendor/bin/drush --include=$repo_root/vendor/acquia/blt/drush blt-doctor -r $repo_root/docroot";
return $this->executeCommandInDrupalVm($command);
}
/**
* Executes `blt doctor` on host machine.
*
* @return \Robo\Result
* The command result.
*/
protected function executeDoctorOnHost($alias) {
$result = $this->taskDrush()
->drush("blt-doctor")
->alias($alias)
->uri("")
->includePath($this->getConfigValue('blt.root') . '/drush')
->printOutput(FALSE)
->printMetadata(FALSE)
->run();
return $result;
}
}