Skip to content

Instantly share code, notes, and snippets.

@jayakrishnanj
Created June 5, 2020 11:17
Show Gist options
  • Save jayakrishnanj/a642708b9f1f9e74fddc55284a1ae65c to your computer and use it in GitHub Desktop.
Save jayakrishnanj/a642708b9f1f9e74fddc55284a1ae65c to your computer and use it in GitHub Desktop.
diff --git a/AcsfToolsCommands.php b/AcsfToolsCommands.php
index 4cc6a00..cdb203f 100755
--- a/AcsfToolsCommands.php
+++ b/AcsfToolsCommands.php
@@ -7,12 +7,17 @@
namespace Drush\Commands\acsf_tools;
use Drush\Drush;
+use Symfony\Component\Process\Exception\ProcessFailedException;
+use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
+use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
/**
* A Drush commandfile.
*/
class AcsfToolsCommands extends AcsfToolsUtils {
+ use SiteAliasManagerAwareTrait;
+
/**
* List the sites of the factory.
*
@@ -218,7 +223,15 @@ class AcsfToolsCommands extends AcsfToolsUtils {
$drush_command_options['uri'] = $domain;
$this->output()->writeln("\n=> Running command on $domain");
- drush_invoke_process('@self', $cmd, $command_args, $drush_command_options);
+
+ $self = $this->siteAliasManager()->getSelf();
+ $process = Drush::drush($self, $cmd, $command_args, $drush_command_options);
+ $exit_code = $process->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($process);
+ }
// Delay in running the command for next site.
if ($delay > 0 && $i < (count($sites) - 1)) {
@@ -264,10 +277,10 @@ class AcsfToolsCommands extends AcsfToolsUtils {
// Look for list of sites and loop over it.
if ($sites = $this->getSites()) {
- $arguments = drush_get_arguments();
+ $arguments = Drush::input()->getArguments();
$command = 'sql-dump';
- $options = drush_get_context('cli');
+ $options = Drush::shell()->getCommandLine();
unset($options['php']);
unset($options['php-options']);
@@ -284,7 +297,14 @@ class AcsfToolsCommands extends AcsfToolsUtils {
$options['uri'] = $domain;
$this->logger()->info("\n=> Running command on $domain");
- drush_invoke_process('@self', $command, $arguments, $options);
+ $self = $this->siteAliasManager()->getSelf();
+ $process = Drush::drush($self, $command, $arguments, $options);
+ $exit_code = $process->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($process);
+ }
}
}
}
@@ -331,9 +351,9 @@ class AcsfToolsCommands extends AcsfToolsUtils {
// Look for list of sites and loop over it.
if ($sites = $this->getSites()) {
- $arguments = drush_get_arguments();
+ $arguments = Drush::input()->getArguments();
- $options = drush_get_context('cli');
+ $options = Drush::shell()->getCommandLine();
unset($options['php']);
unset($options['php-options']);
unset($options['source-folder']);
@@ -356,7 +376,14 @@ class AcsfToolsCommands extends AcsfToolsUtils {
// Temporary decompress the dump to be used with drush sql-cli.
if ($gzip) {
- drush_shell_exec('gunzip -k ' . $source_file);
+ $shell_execution = Drush::shell('gunzip -k ' . $source_file);
+ $exit_code = $shell_execution->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($shell_execution);
+ }
+
$source_file = substr($source_file, 0, -3);
}
@@ -366,15 +393,42 @@ class AcsfToolsCommands extends AcsfToolsUtils {
$options['uri'] = $domain;
$this->logger()->info("\n=> Dropping and restoring database on $domain");
- $result = drush_invoke_process('@self', 'sql-connect', $arguments, $options, ['output' => FALSE]);
+ $self = $this->siteAliasManager()->getSelf();
+ $result = Drush::drush($self, 'sql-connect', $arguments, $options, ['output' => FALSE]);
+ $exit_code = $result->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($exit_code);
+ }
+
if (!empty($result['object'])) {
- drush_invoke_process('@self', 'sql-drop', $arguments, $options);
- drush_shell_exec($result['object'] . ' < ' . $source_file);
+ $result = Drush::drush($self, 'sql-drop', $arguments, $options);
+ $exit_code = $result->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($exit_code);
+ }
+
+ $shell_execution = Drush::shell($result['object'] . ' < ' . $source_file);
+ $exit_code = $shell_execution->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($shell_execution);
+ }
}
// Remove the temporary decompressed dump
if ($gzip) {
- drush_shell_exec('rm ' . $source_file);
+ $shell_execution = Drush::shell('rm ' . $source_file);
+ $exit_code = $shell_execution->run();
+
+ if ($exit_code !== 0) {
+ // Throw an exception with details about the failed process.
+ throw new ProcessFailedException($shell_execution);
+ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment