You are here

function drush_exec in Acquia Cloud Site Factory Connector 8

Same name and namespace in other branches
  1. 8.2 acsf_init/lib/cloud_hooks/common/post-db-copy/000-acquia_required_scrub.php \drush_exec()

Runs Drush command. Exits with error code if something fails.

Parameters

string $site: Target site.

string $env: Target environment.

string $domain: Target domain.

string $cmd: Command that will be run.

1 call to drush_exec()
000-acquia_required_scrub.php in acsf_init/lib/cloud_hooks/common/post-db-copy/000-acquia_required_scrub.php
Scrubs a site after its database has been copied.

File

acsf_init/lib/cloud_hooks/common/post-db-copy/000-acquia_required_scrub.php, line 70
Scrubs a site after its database has been copied.

Code

function drush_exec(string $site, string $env, string $domain, string $cmd) {
  $docroot = sprintf('/var/www/html/%s.%s/docroot', $site, $env);
  $drush_cmd = sprintf('DRUSH_PATHS_CACHE_DIRECTORY=%1$s CACHE_PREFIX=%1$s AH_SITE_ENVIRONMENT=%2$s \\drush8 -r %3$s -l %4$s -y %5$s 2>&1', escapeshellarg(drush_cache_path($site, $env, $domain)), escapeshellarg($env), escapeshellarg($docroot), escapeshellarg('https://' . $domain), $cmd);
  fwrite(STDERR, "Executing: {$drush_cmd};\n");
  $result = 0;
  $output = [];

  // Acquia rules disallow exec() with dynamic arguments.
  // phpcs:disable
  exec($drush_cmd, $output, $result);

  // phpcs:enable
  print implode("\n", $output);
  fwrite(STDERR, "Command execution returned status code: {$result}\n");

  // In case the returned status code ($result) is not 0, we'll remove the drush
  // cache directory and halt the execution of the whole script.
  if ($result) {
    rmdir_r(drush_cache_path($site, $env, $domain));
    exit($result);
  }
  return $output;
}