Skip to content

Commit

Permalink
Fixes acquia#1408: Porting doctor command to Robo. (acquia#1417)
Browse files Browse the repository at this point in the history
* Porting doctor command to Robo.

* Moving chmod.

* Fixing BLT doctor in VM.

* PHPCS fix.

* Improving DR VM integration.
  • Loading branch information
grasmash authored Apr 24, 2017
1 parent fad1d20 commit b6930e2
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 72 deletions.
1 change: 1 addition & 0 deletions bin/blt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $robo_namespaces = [
'vm',
];
$robo_commands = [
'doctor'
];

$params_string = implode(' ', array_slice($argv, 1));
Expand Down
19 changes: 0 additions & 19 deletions phing/tasks/blt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,6 @@
<exec dir="${repo.root}" command="git commit -m 'Initial commit.'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>

<target name="doctor" description="Inspects your local blt configuration for possible issues.">
<drush command="status" returnProperty="drush.return" haltonerror="false" passthru="false" verbose="false" logoutput="false">
<option name="include">../vendor/acquia/blt/drush</option>
</drush>
<if>
<equals arg1="${drush.return}" arg2="0"/>
<then>
<drush command="blt-doctor" verbose="false" dir="${docroot}">
<option name="include">../vendor/acquia/blt/drush</option>
</drush>
</then>
<else>
<drush command="blt-doctor" verbose="false" dir="${docroot}" alias="" uri="">
<option name="include">../vendor/acquia/blt/drush</option>
</drush>
</else>
</if>
</target>

<target name="blt:rsync-template" hidden="true">
<echo>Copying files from BLT's template into your project...</echo>
<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"/>
Expand Down
2 changes: 2 additions & 0 deletions scripts/drupal-vm/post-provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ then
VAGRANT_MACHINE_NAME=$(grep vagrant_machine_name: "$CONFIG_FILE" | cut -d' ' -f 2)
REPO_ROOT=/var/www/${VAGRANT_MACHINE_NAME}
cd ${REPO_ROOT}
else
echo "Could not find repo root!"
fi

# Add blt alias to front of .bashrc so that it applies to non-interactive shells.
Expand Down
90 changes: 90 additions & 0 deletions src/Robo/Commands/Blt/DoctorCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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() {

if ($this->getInspector()->isDrupalVmLocallyInitialized() && $this->getInspector()->isDrupalVmBooted()) {
$result = $this->executeDoctorInsideVm();
if ($result->wasSuccessful()) {
return $result;
}
}

// Try BLT doctor with default alias. This might be a Drupal VM alias.
$alias = $this->getConfigValue('drush.alias');
$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. Trying with @self...");
$this->executeDoctorOnHost('self');
}

return $result;
}

/**
* 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 a command inside of Drupal VM.
*
* @param string $command
* The command to execute.
*
* @return \Robo\Result
* The command result.
*/
protected function executeCommandInDrupalVm($command) {
$result = $this->taskExec("vagrant exec '$command'")
->dir($this->getConfigValue('repo.root'))
->detectInteractive()
->run();

return $result;
}

/**
* Executes `blt doctor` on host machine.
*
* @return \Robo\Result
* The command result.
*/
protected function executeDoctorOnHost($alias) {
$drush_bin = $this->getConfigValue('composer.bin') . '/drush';
$include_dir = $this->getConfigValue('blt.root') . '/drush';
$result = $this->taskExec("$drush_bin @$alias --include=$include_dir blt-doctor")
->dir($this->getConfigValue('docroot'))
->detectInteractive()
->run();

return $result;
}

}
2 changes: 2 additions & 0 deletions src/Robo/Commands/BltReleaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class BltReleaseCommand extends BltTasks {
*
* @option $update-changelog Update CHANGELOG.md. Defaults to true.
*
* @hidden
*
* @return int
* The CLI status code.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Robo/Commands/Setup/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class BuildCommand extends BltTasks {
* Install dependencies, builds docroot, installs Drupal.
*
* @command setup
*
* @aliases setup:all
*/
public function setup() {
$this->say("Setting up local environment");
$this->say("Setting up local environment...");
$status_code = $this->invokeCommands([
'setup:build',
'setup:hash-salt',
Expand Down Expand Up @@ -107,7 +109,7 @@ public function build() {
}

/**
* Installs composer dependencies.
* Installs Composer dependencies.
*
* @command setup:composer:install
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Robo/Commands/Setup/CloudHooksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class CloudHooksCommand extends BltTasks {

/**
* Installs Acquia cloud hooks to hooks.
* Installs Acquia cloud hooks.
*
* @command setup:cloud-hooks
*/
Expand Down
104 changes: 68 additions & 36 deletions src/Robo/Commands/Setup/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function update() {
}

/**
* Import configuration from the config directory.
* Imports configuration from the config directory according to cm.strategy.
*
* @command setup:config-import
*/
Expand Down Expand Up @@ -52,49 +52,18 @@ public function import() {

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

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

case 'features':
$task->exec("drush @$drush_alias config-import $cm_core_key --partial --yes");
if ($this->getConfig()->has('cm.features.bundle"')) {
$task->exec("drush @$drush_alias pm-enable features --yes");
// Clear drush caches to register features drush commands.
$task->exec("drush cc drush --yes");
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
// Revert all features again!
// @see https://www.drupal.org/node/2851532
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
}
}
if ($this->getConfigValue('cm.features.no-overrides')) {
$this->say("Checking for features overrides...");
if ($this->getConfig()->has('cm.features.bundle')) {
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
$features_overriden = $task->exec("drush fl --bundle=${bundle} | grep -Ei '(changed|conflicts|added)( *)$");
// @todo emit:
// A feature in the ${bundle} bundle is overridden. You must
// re-export this feature to incorporate the changes.
// @todo throw Exception.
}
}
}
$this->importFeatures($task, $drush_alias, $cm_core_key);
break;
}

$task->exec("drush @$drush_alias cache-rebuild");
$task->run();

Expand All @@ -103,4 +72,67 @@ public function import() {
}
}

/**
* Import configuration using core config management only.
*
* @param $task
* @param $drush_alias
* @param $cm_core_key
*/
protected function importCoreOnly($task, $drush_alias, $cm_core_key) {
if (file_exists($this->getConfigValue("cm.core.dirs.$cm_core_key.path") . '/core.extension.yml')) {
$task->exec("drush @$drush_alias config-import $cm_core_key --yes");
}
}

/**
* Import configuration using config_split module.
*
* @param $task
* @param $drush_alias
*/
protected function importConfigSplit($task, $drush_alias) {
// We cannot use ${cm.core.dirs.${cm.core.key}.path} here because
// cm.core.key may be 'vcs', which does not have a path defined in
// BLT config. Perhaps this should be refactored.
$core_config_file = $this->getConfigValue('docroot') . '/' . $this->getConfigValue('cm.core.dirs.sync.path') . '/core.extension.yml';
if (file_exists($core_config_file)) {
$task->exec("drush @$drush_alias pm-enable config_split --yes");
$task->exec("drush @$drush_alias config-import sync --yes");
}
}

/**
* Import configuration using features module.
* @param $task
* @param $drush_alias
* @param $cm_core_key
*/
protected function importFeatures($task, $drush_alias, $cm_core_key) {
$task->exec("drush @$drush_alias config-import $cm_core_key --partial --yes");
if ($this->getConfig()->has('cm.features.bundle"')) {
$task->exec("drush @$drush_alias pm-enable features --yes");
// Clear drush caches to register features drush commands.
$task->exec("drush cc drush --yes");
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
// Revert all features again!
// @see https://www.drupal.org/node/2851532
$task->exec("drush @$drush_alias features-revert-all --bundle=$bundle --yes");
}
}
if ($this->getConfigValue('cm.features.no-overrides')) {
$this->say("Checking for features overrides...");
if ($this->getConfig()->has('cm.features.bundle')) {
foreach ($this->getConfigValue('cm.features.bundle') as $bundle) {
$features_overriden = $task->exec("drush fl --bundle=${bundle} | grep -Ei '(changed|conflicts|added)( *)$");
// @todo emit:
// A feature in the ${bundle} bundle is overridden. You must
// re-export this feature to incorporate the changes.
// @todo throw Exception.
}
}
}
}

}
9 changes: 5 additions & 4 deletions src/Robo/Commands/Setup/SettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public function generateSiteConfigFiles() {

$this->taskFilesystemStack()
->chmod($multisite_dir, 0777)
// @todo Might need to check that this file exists before chmoding it.
->chmod($project_settings_file, 0777)
->copy($project_default_settings_file, $project_settings_file)
->copy($project_settings_file, 0777)
->copy($blt_local_settings_file, $default_local_settings_file)
->copy($default_local_settings_file, $project_local_settings_file)
->copy($blt_local_drush_file, $default_local_drush_file)
Expand Down Expand Up @@ -87,7 +88,7 @@ public function generateSiteConfigFiles() {
* @command setup:behat
*/
public function behat() {
$this->say("Generating Behat configuration files");
$this->say("Generating Behat configuration files...");
$this->taskFilesystemStack()
->copy($this->defaultBehatLocalConfigFile, $this->projectBehatLocalConfigFile)
->stopOnFail()
Expand All @@ -97,7 +98,7 @@ public function behat() {
}

/**
* Installs git hooks to local .git/hooks directory.
* Installs BLT git hooks to local .git/hooks directory.
*
* @command setup:git-hooks
*/
Expand All @@ -117,7 +118,7 @@ public function gitHooks() {
*/
protected function installGitHook($hook) {
if ($this->getConfigValue('git.hooks.' . $hook)) {
$this->say("Installing $hook git hook");
$this->say("Installing $hook git hook...");
$source = $this->getConfigValue('git.hooks.' . $hook) . "/$hook";
$dest = $this->getConfigValue('repo.root') . "/.git/hooks/$hook";

Expand Down
Loading

0 comments on commit b6930e2

Please sign in to comment.