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

Commit b6930e2

Browse files
authored
Fixes #1408: Porting doctor command to Robo. (#1417)
* Porting doctor command to Robo. * Moving chmod. * Fixing BLT doctor in VM. * PHPCS fix. * Improving DR VM integration.
1 parent fad1d20 commit b6930e2

12 files changed

+221
-72
lines changed

bin/blt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $robo_namespaces = [
1818
'vm',
1919
];
2020
$robo_commands = [
21+
'doctor'
2122
];
2223

2324
$params_string = implode(' ', array_slice($argv, 1));

phing/tasks/blt.xml

-19
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,6 @@
6363
<exec dir="${repo.root}" command="git commit -m 'Initial commit.'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
6464
</target>
6565

66-
<target name="doctor" description="Inspects your local blt configuration for possible issues.">
67-
<drush command="status" returnProperty="drush.return" haltonerror="false" passthru="false" verbose="false" logoutput="false">
68-
<option name="include">../vendor/acquia/blt/drush</option>
69-
</drush>
70-
<if>
71-
<equals arg1="${drush.return}" arg2="0"/>
72-
<then>
73-
<drush command="blt-doctor" verbose="false" dir="${docroot}">
74-
<option name="include">../vendor/acquia/blt/drush</option>
75-
</drush>
76-
</then>
77-
<else>
78-
<drush command="blt-doctor" verbose="false" dir="${docroot}" alias="" uri="">
79-
<option name="include">../vendor/acquia/blt/drush</option>
80-
</drush>
81-
</else>
82-
</if>
83-
</target>
84-
8566
<target name="blt:rsync-template" hidden="true">
8667
<echo>Copying files from BLT's template into your project...</echo>
8768
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --exclude-from=${blt.update.ignore-existing-file}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>

scripts/drupal-vm/post-provision.sh

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ then
77
VAGRANT_MACHINE_NAME=$(grep vagrant_machine_name: "$CONFIG_FILE" | cut -d' ' -f 2)
88
REPO_ROOT=/var/www/${VAGRANT_MACHINE_NAME}
99
cd ${REPO_ROOT}
10+
else
11+
echo "Could not find repo root!"
1012
fi
1113

1214
# Add blt alias to front of .bashrc so that it applies to non-interactive shells.
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Acquia\Blt\Robo\Commands\Blt;
4+
5+
use Acquia\Blt\Robo\BltTasks;
6+
use Symfony\Component\Yaml\Yaml;
7+
8+
/**
9+
* Defines commands in the "blt:doctor" namespace.
10+
*/
11+
class DoctorCommand extends BltTasks {
12+
13+
/**
14+
* Inspects your local blt configuration for possible issues.
15+
*
16+
* @command doctor
17+
*/
18+
public function doctor() {
19+
20+
if ($this->getInspector()->isDrupalVmLocallyInitialized() && $this->getInspector()->isDrupalVmBooted()) {
21+
$result = $this->executeDoctorInsideVm();
22+
if ($result->wasSuccessful()) {
23+
return $result;
24+
}
25+
}
26+
27+
// Try BLT doctor with default alias. This might be a Drupal VM alias.
28+
$alias = $this->getConfigValue('drush.alias');
29+
$result = $this->executeDoctorOnHost($alias);
30+
31+
// If default alias failed, try again using @self alias.
32+
if (!$result->wasSuccessful() && $alias != 'self') {
33+
$this->logger->warning("Unable to run the doctor using @$alias. Trying with @self...");
34+
$this->executeDoctorOnHost('self');
35+
}
36+
37+
return $result;
38+
}
39+
40+
/**
41+
* Executes `blt doctor` inside Drupal VM.
42+
*
43+
* @return \Robo\Result
44+
* The command result.
45+
*/
46+
protected function executeDoctorInsideVm() {
47+
$drupal_vm_config = Yaml::parse(file_get_contents($this->getConfigValue('repo.root') . '/box/config.yml'));
48+
$repo_root = $drupal_vm_config['vagrant_synced_folders'][0]['destination'];
49+
$this->say("Drupal VM was detected. Running blt doctor inside of VM...");
50+
$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";
51+
52+
return $this->executeCommandInDrupalVm($command);
53+
}
54+
55+
/**
56+
* Executes a command inside of Drupal VM.
57+
*
58+
* @param string $command
59+
* The command to execute.
60+
*
61+
* @return \Robo\Result
62+
* The command result.
63+
*/
64+
protected function executeCommandInDrupalVm($command) {
65+
$result = $this->taskExec("vagrant exec '$command'")
66+
->dir($this->getConfigValue('repo.root'))
67+
->detectInteractive()
68+
->run();
69+
70+
return $result;
71+
}
72+
73+
/**
74+
* Executes `blt doctor` on host machine.
75+
*
76+
* @return \Robo\Result
77+
* The command result.
78+
*/
79+
protected function executeDoctorOnHost($alias) {
80+
$drush_bin = $this->getConfigValue('composer.bin') . '/drush';
81+
$include_dir = $this->getConfigValue('blt.root') . '/drush';
82+
$result = $this->taskExec("$drush_bin @$alias --include=$include_dir blt-doctor")
83+
->dir($this->getConfigValue('docroot'))
84+
->detectInteractive()
85+
->run();
86+
87+
return $result;
88+
}
89+
90+
}

src/Robo/Commands/BltReleaseCommand.php

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class BltReleaseCommand extends BltTasks {
2525
*
2626
* @option $update-changelog Update CHANGELOG.md. Defaults to true.
2727
*
28+
* @hidden
29+
*
2830
* @return int
2931
* The CLI status code.
3032
*/

src/Robo/Commands/Setup/BuildCommand.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ class BuildCommand extends BltTasks {
1515
* Install dependencies, builds docroot, installs Drupal.
1616
*
1717
* @command setup
18+
*
19+
* @aliases setup:all
1820
*/
1921
public function setup() {
20-
$this->say("Setting up local environment");
22+
$this->say("Setting up local environment...");
2123
$status_code = $this->invokeCommands([
2224
'setup:build',
2325
'setup:hash-salt',
@@ -107,7 +109,7 @@ public function build() {
107109
}
108110

109111
/**
110-
* Installs composer dependencies.
112+
* Installs Composer dependencies.
111113
*
112114
* @command setup:composer:install
113115
*/

src/Robo/Commands/Setup/CloudHooksCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class CloudHooksCommand extends BltTasks {
1111

1212
/**
13-
* Installs Acquia cloud hooks to hooks.
13+
* Installs Acquia cloud hooks.
1414
*
1515
* @command setup:cloud-hooks
1616
*/

src/Robo/Commands/Setup/ConfigCommand.php

+68-36
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function update() {
2121
}
2222

2323
/**
24-
* Import configuration from the config directory.
24+
* Imports configuration from the config directory according to cm.strategy.
2525
*
2626
* @command setup:config-import
2727
*/
@@ -52,49 +52,18 @@ public function import() {
5252

5353
switch ($strategy) {
5454
case 'core-only':
55-
if (file_exists($this->getConfigValue("cm.core.dirs.$cm_core_key.path") . '/core.extension.yml')) {
56-
$task->exec("drush @$drush_alias config-import $cm_core_key --yes");
57-
}
55+
$this->importCoreOnly($task, $drush_alias, $cm_core_key);
5856
break;
5957

6058
case 'config-split':
61-
// We cannot use ${cm.core.dirs.${cm.core.key}.path} here because
62-
// cm.core.key may be 'vcs', which does not have a path defined in
63-
// BLT config. Perhaps this should be refactored.
64-
$core_config_file = $this->getConfigValue('docroot') . '/' . $this->getConfigValue('cm.core.dirs.sync.path') . '/core.extension.yml';
65-
if (file_exists($core_config_file)) {
66-
$task->exec("drush @$drush_alias pm-enable config_split --yes");
67-
$task->exec("drush @$drush_alias config-import sync --yes");
68-
}
59+
$this->importConfigSplit($task, $drush_alias);
6960
break;
7061

7162
case 'features':
72-
$task->exec("drush @$drush_alias config-import $cm_core_key --partial --yes");
73-
if ($this->getConfig()->has('cm.features.bundle"')) {
74-
$task->exec("drush @$drush_alias pm-enable features --yes");
75-
// Clear drush caches to register features drush commands.
76-
$task->exec("drush cc drush --yes");
77-
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
78-
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
79-
// Revert all features again!
80-
// @see https://www.drupal.org/node/2851532
81-
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
82-
}
83-
}
84-
if ($this->getConfigValue('cm.features.no-overrides')) {
85-
$this->say("Checking for features overrides...");
86-
if ($this->getConfig()->has('cm.features.bundle')) {
87-
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
88-
$features_overriden = $task->exec("drush fl --bundle=${bundle} | grep -Ei '(changed|conflicts|added)( *)$");
89-
// @todo emit:
90-
// A feature in the ${bundle} bundle is overridden. You must
91-
// re-export this feature to incorporate the changes.
92-
// @todo throw Exception.
93-
}
94-
}
95-
}
63+
$this->importFeatures($task, $drush_alias, $cm_core_key);
9664
break;
9765
}
66+
9867
$task->exec("drush @$drush_alias cache-rebuild");
9968
$task->run();
10069

@@ -103,4 +72,67 @@ public function import() {
10372
}
10473
}
10574

75+
/**
76+
* Import configuration using core config management only.
77+
*
78+
* @param $task
79+
* @param $drush_alias
80+
* @param $cm_core_key
81+
*/
82+
protected function importCoreOnly($task, $drush_alias, $cm_core_key) {
83+
if (file_exists($this->getConfigValue("cm.core.dirs.$cm_core_key.path") . '/core.extension.yml')) {
84+
$task->exec("drush @$drush_alias config-import $cm_core_key --yes");
85+
}
86+
}
87+
88+
/**
89+
* Import configuration using config_split module.
90+
*
91+
* @param $task
92+
* @param $drush_alias
93+
*/
94+
protected function importConfigSplit($task, $drush_alias) {
95+
// We cannot use ${cm.core.dirs.${cm.core.key}.path} here because
96+
// cm.core.key may be 'vcs', which does not have a path defined in
97+
// BLT config. Perhaps this should be refactored.
98+
$core_config_file = $this->getConfigValue('docroot') . '/' . $this->getConfigValue('cm.core.dirs.sync.path') . '/core.extension.yml';
99+
if (file_exists($core_config_file)) {
100+
$task->exec("drush @$drush_alias pm-enable config_split --yes");
101+
$task->exec("drush @$drush_alias config-import sync --yes");
102+
}
103+
}
104+
105+
/**
106+
* Import configuration using features module.
107+
* @param $task
108+
* @param $drush_alias
109+
* @param $cm_core_key
110+
*/
111+
protected function importFeatures($task, $drush_alias, $cm_core_key) {
112+
$task->exec("drush @$drush_alias config-import $cm_core_key --partial --yes");
113+
if ($this->getConfig()->has('cm.features.bundle"')) {
114+
$task->exec("drush @$drush_alias pm-enable features --yes");
115+
// Clear drush caches to register features drush commands.
116+
$task->exec("drush cc drush --yes");
117+
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
118+
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
119+
// Revert all features again!
120+
// @see https://www.drupal.org/node/2851532
121+
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
122+
}
123+
}
124+
if ($this->getConfigValue('cm.features.no-overrides')) {
125+
$this->say("Checking for features overrides...");
126+
if ($this->getConfig()->has('cm.features.bundle')) {
127+
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
128+
$features_overriden = $task->exec("drush fl --bundle=${bundle} | grep -Ei '(changed|conflicts|added)( *)$");
129+
// @todo emit:
130+
// A feature in the ${bundle} bundle is overridden. You must
131+
// re-export this feature to incorporate the changes.
132+
// @todo throw Exception.
133+
}
134+
}
135+
}
136+
}
137+
106138
}

src/Robo/Commands/Setup/SettingsCommand.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public function generateSiteConfigFiles() {
5555

5656
$this->taskFilesystemStack()
5757
->chmod($multisite_dir, 0777)
58+
// @todo Might need to check that this file exists before chmoding it.
59+
->chmod($project_settings_file, 0777)
5860
->copy($project_default_settings_file, $project_settings_file)
59-
->copy($project_settings_file, 0777)
6061
->copy($blt_local_settings_file, $default_local_settings_file)
6162
->copy($default_local_settings_file, $project_local_settings_file)
6263
->copy($blt_local_drush_file, $default_local_drush_file)
@@ -87,7 +88,7 @@ public function generateSiteConfigFiles() {
8788
* @command setup:behat
8889
*/
8990
public function behat() {
90-
$this->say("Generating Behat configuration files");
91+
$this->say("Generating Behat configuration files...");
9192
$this->taskFilesystemStack()
9293
->copy($this->defaultBehatLocalConfigFile, $this->projectBehatLocalConfigFile)
9394
->stopOnFail()
@@ -97,7 +98,7 @@ public function behat() {
9798
}
9899

99100
/**
100-
* Installs git hooks to local .git/hooks directory.
101+
* Installs BLT git hooks to local .git/hooks directory.
101102
*
102103
* @command setup:git-hooks
103104
*/
@@ -117,7 +118,7 @@ public function gitHooks() {
117118
*/
118119
protected function installGitHook($hook) {
119120
if ($this->getConfigValue('git.hooks.' . $hook)) {
120-
$this->say("Installing $hook git hook");
121+
$this->say("Installing $hook git hook...");
121122
$source = $this->getConfigValue('git.hooks.' . $hook) . "/$hook";
122123
$dest = $this->getConfigValue('repo.root') . "/.git/hooks/$hook";
123124

0 commit comments

Comments
 (0)