Skip to content

Commit

Permalink
Adding setup:toggle-modules command.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Jun 1, 2017
1 parent d727eee commit 6ebf6d6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
3 changes: 3 additions & 0 deletions scripts/blt/ci/internal/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ mv ${BLT_DIR}/scripts/blt/ci/internal/config_split.config_split.ci.yml config/de
blt setup:config-import
drush pm-uninstall config_split --root=docroot -y

# Test cloud hooks.


# Test SimpleSAMLphp configuration.
blt simplesamlphp:init

Expand Down
60 changes: 60 additions & 0 deletions src/Robo/Commands/Setup/ToggleModulesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Acquia\Blt\Robo\Commands\Setup;

use Acquia\Blt\Robo\BltTasks;
use Robo\Contract\VerbosityThresholdInterface;
use Symfony\Component\Finder\Finder;

/**
* Defines commands in the "setup:toggle-modules" namespace.
*/
class ToggleModulesCommand extends BltTasks {

/**
* Enables and uninstalls specified modules.
*
* @command setup:toggle-modules
*/
public function toggleModules() {
if (!empty($_ENV['environment'])) {
// Enable modules.
$enable_key = "modules.{$_ENV['environment']}.enable";
$exit_code = $this->doToggleModules('pm-enable', $enable_key);

// Uninstall modules.
$disable_key = "modules.{$_ENV['environment']}.uninstall";
$exit_code = $this->doToggleModules('pm-uninstall', $disable_key);

return $exit_code;
}
}

/**
* Enables or uninstalls an array of modules.
*
* @param string $command
* The drush command to execute. E.g., pm-enable or pm-uninstall.
* @param string $config_key
* The config key containing the array of modules.
*
* @return int
* The exit code of the command.
*/
protected function doToggleModules($command, $config_key) {
if ($this->getConfig()->has($config_key)) {
$modules = $this->getConfigValue($config_key);
$modules_list = implode(' ', $modules);
$result = $this->taskDrush()
->drush("$command $modules_list --skip")
->run();
$exit_code = $result->getExitCode();
}
else {
$exit_code = 0;
$this->logger->info("$config_key is not set.");
}

return $exit_code;
}
}
4 changes: 2 additions & 2 deletions src/Robo/Commands/Vm/VmCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function localInitialize() {
file_put_contents($filename, $yaml);

$this->say("<comment>$filename</comment> was modified.");
$this->say("BLT will now use <comment>@{$contents['drush']['default_alias']}</comment> as the default drush alias for all commands.");
$this->say("BLT will now use <comment>@{$contents['drush']['default_alias']}</comment> as the default drush alias for all commands on this machine.");
}

/**
Expand All @@ -184,7 +184,7 @@ protected function boot() {
$this->checkRequirements();
$confirm = $this->confirm("Do you want to boot Drupal VM?", TRUE);
if ($confirm) {
$this->say("In future, run <comment>vagrant up</comment> to boot the VM");
$this->say("In future, run <comment>vagrant up</comment> to boot the VM.");
$result = $this->taskExec("vagrant up")
->dir($this->getConfigValue('repo.root'))
->printOutput(TRUE)
Expand Down
4 changes: 2 additions & 2 deletions src/Robo/Common/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function execute($command) {
* The port number.
*/
public function killProcessByPort($port) {
$this->logger->info("Killing all processes on port $port");
$this->logger->info("Killing all processes on port '$port'...");
// This is allowed to fail.
// @todo Replace with standardized call to Symfony Process.
exec("command -v lsof && lsof -ti tcp:$port | xargs kill l 2>&1");
Expand All @@ -128,7 +128,7 @@ public function killProcessByPort($port) {
* The name of the process.
*/
public function killProcessByName($name) {
$this->logger->info("Killing all processing containing string '$name'");
$this->logger->info("Killing all processing containing string '$name'...");
// This is allowed to fail.
// @todo Replace with standardized call to Symfony Process.
exec("ps aux | grep -i $name | grep -v grep | awk '{print $2}' | xargs kill -9 2>&1");
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Hooks/CommandEventHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function skipDisabledCommands(ConsoleCommandEvent $event) {
* @hook command-event *
*/
public function executeInDrupalVm(ConsoleCommandEvent $event) {
// @todo Create global option to opt-out of this. E.g., --execute-on-host.
$command = $event->getCommand();
if (method_exists($command, 'getAnnotationData')) {
/* @var \Consolidation\AnnotatedCommand\AnnotationData */
Expand Down
2 changes: 2 additions & 0 deletions src/Update/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,7 @@ public function update_8009000() {
$this->updater->getOutput()->writeln("<comment>blt/composer.overrides.json</comment> is no longer necessary.");
$this->updater->getOutput()->writeln("Instead, move your overrides to your root composer.json, and set extra.merge-plugin.ignore-duplicates to true.");
}

$this->updater->writeProjectYml($project_yml);
}
}

0 comments on commit 6ebf6d6

Please sign in to comment.