From 27cbc7ad32547038928693f04d4f02af49452a5a Mon Sep 17 00:00:00 2001 From: Lindsey Catlett Date: Tue, 4 Dec 2018 10:32:48 -0500 Subject: [PATCH] Multisite bugfixes (#3231) * Fix multisite test alias bug. * Fix default drush local multisite alias bug causing test failures. * Fix global varible scope and phpcs syntax. * Update variable names and fix phpcs validation errors.. --- .../post-install/post-install.php | 37 ++++++------------- .../post-settings-php/memcache.php | 8 ++-- .../factory-hooks/post-sites-php/includes.php | 10 +++-- settings/blt.settings.php | 2 +- settings/config.settings.php | 2 +- .../Commands/Generate/MultisiteCommand.php | 2 +- tests/phpunit/Blt/MultiSiteTest.php | 2 +- 7 files changed, 26 insertions(+), 37 deletions(-) diff --git a/scripts/factory-hooks/post-install/post-install.php b/scripts/factory-hooks/post-install/post-install.php index c2ae32258..ca5bd4b9b 100755 --- a/scripts/factory-hooks/post-install/post-install.php +++ b/scripts/factory-hooks/post-install/post-install.php @@ -14,30 +14,21 @@ * */ -use Drush\Drush; -use Drupal\Component\FileCache\FileCacheFactory; -use Drupal\Core\Database\Database; -use Drupal\Core\Site\Settings; - -global $acsf_site_name; - -// Acquia hosting site / environment names -/*$site = getenv('AH_SITE_GROUP'); +// Acquia hosting site / environment names. +$site = getenv('AH_SITE_GROUP'); $env = getenv('AH_SITE_ENVIRONMENT'); -$uri = FALSE;*/ +$uri = FALSE; -$site = 'SANDBOX'; -$env = 'local'; -$uri = 'local.sandbox.com'; +global $_acsf_site_name; -// ACSF Database Role - if (!empty($GLOBALS['gardens_site_settings']['conf']['acsf_db_name'])) { - $db_role = $GLOBALS['gardens_site_settings']['conf']['acsf_db_name']; - } +// ACSF Database Role. +if (!empty($GLOBALS['gardens_site_settings']['conf']['acsf_db_name'])) { + $db_role = $GLOBALS['gardens_site_settings']['conf']['acsf_db_name']; +} $docroot = sprintf('/var/www/html/%s.%s/docroot', $site, $env); -// BLT executable +// BLT executable. $blt = sprintf('/var/www/html/%s.%s/vendor/bin/blt', $site, $env); /** @@ -51,7 +42,7 @@ function error($message) { exit(1); } -fwrite(STDERR, sprintf("Running updates on: site: %s; env: %s; db_role: %s; name: %s;\n", $site, $env, $db_role, $acsf_site_name)); +fwrite(STDERR, sprintf("Running updates on: site: %s; env: %s; db_role: %s; name: %s;\n", $site, $env, $db_role, $_acsf_site_name)); include_once $docroot . '/sites/g/sites.inc'; $sites_json = gardens_site_data_load_file(); @@ -72,13 +63,11 @@ function error($message) { $docroot = sprintf('/var/www/html/%s.%s/docroot', $site, $env); -//$cache_directory = sprintf('/mnt/tmp/%s.%s/drush_tmp_cache/%s', $site, $env, md5($uri)); -//cacheDir=`/usr/bin/env php /mnt/www/html/$site.$env/vendor/acquia/blt/scripts/blt/drush/cache.php $site $env $uri` $cache_directory = exec("/mnt/www/html/$site.$env/vendor/acquia/blt/scripts/blt/drush/cache.php $site $env $uri"); shell_exec(sprintf('mkdir -p %s', escapeshellarg($cache_directory))); -// Execute the updates +// Execute the updates. $command = sprintf( 'DRUSH_PATHS_CACHE_DIRECTORY=%s %s drupal:update --environment=%s --site=%s --define drush.uri=%s --verbose --yes --no-interaction', escapeshellarg($cache_directory), @@ -92,7 +81,7 @@ function error($message) { $result = 0; $output = array(); exec($command, $output, $result); -print join("\n", $output); +print implode("\n", $output); // Clean up the drush cache directory. shell_exec(sprintf('rm -rf %s', escapeshellarg($cache_directory))); @@ -101,5 +90,3 @@ function error($message) { fwrite(STDERR, "Command execution returned status code: $result!\n"); exit($result); } - - diff --git a/scripts/factory-hooks/post-settings-php/memcache.php b/scripts/factory-hooks/post-settings-php/memcache.php index 1de92d16f..6413ed314 100644 --- a/scripts/factory-hooks/post-settings-php/memcache.php +++ b/scripts/factory-hooks/post-settings-php/memcache.php @@ -8,11 +8,9 @@ */ // Use ACSF internal settings site flag to apply memcache settings. -if (getenv('AH_SITE_ENVIRONMENT') && - isset($site_settings['flags']['memcache_enabled']) && - isset($settings['memcache']['servers']) +if (getenv('AH_SITE_ENVIRONMENT') && + isset($site_settings['flags']['memcache_enabled']) && + isset($settings['memcache']['servers']) ) { require DRUPAL_ROOT . '/../vendor/acquia/blt/settings/memcache.settings.php'; } - - diff --git a/scripts/factory-hooks/post-sites-php/includes.php b/scripts/factory-hooks/post-sites-php/includes.php index 0486d4376..d5efc4aa5 100644 --- a/scripts/factory-hooks/post-sites-php/includes.php +++ b/scripts/factory-hooks/post-sites-php/includes.php @@ -1,12 +1,15 @@ get('multisites'); if (in_array($name, $acsf_sites)) { - $acsf_site_name = $name; + $_acsf_site_name = $name; } } } diff --git a/settings/config.settings.php b/settings/config.settings.php index 67968d3f0..d563475f9 100644 --- a/settings/config.settings.php +++ b/settings/config.settings.php @@ -96,7 +96,7 @@ $config["$split_filename_prefix.$site_dir"]['status'] = TRUE; // Set acsf site split if explicit global exists. -if (isset($acsf_site_name)) { +if (isset($_acsf_site_name)) { $config["$split_filename_prefix.$acsf_site_name"]['status'] = TRUE; } diff --git a/src/Robo/Commands/Generate/MultisiteCommand.php b/src/Robo/Commands/Generate/MultisiteCommand.php index e74656585..c4ff08a80 100644 --- a/src/Robo/Commands/Generate/MultisiteCommand.php +++ b/src/Robo/Commands/Generate/MultisiteCommand.php @@ -187,7 +187,7 @@ protected function createNewBltSiteYml( $site_yml['project']['human_name'] = $site_name; $site_yml['project']['local']['protocol'] = $url['scheme']; $site_yml['project']['local']['hostname'] = $url['host']; - $site_yml['drush']['aliases']['local'] = $site_name . ".local"; + $site_yml['drush']['aliases']['local'] = "self"; $site_yml['drush']['aliases']['remote'] = $remote_alias; YamlMunge::mergeArrayIntoFile($site_yml, $site_yml_filename); } diff --git a/tests/phpunit/Blt/MultiSiteTest.php b/tests/phpunit/Blt/MultiSiteTest.php index 799b7c560..3aba676bd 100644 --- a/tests/phpunit/Blt/MultiSiteTest.php +++ b/tests/phpunit/Blt/MultiSiteTest.php @@ -42,7 +42,7 @@ public function testMultisiteGenerate() { $this->assertEquals("$this->site1Dir.clone", $site1_blt_yml['drush']['aliases']['remote']); $site2_blt_yml = YamlMunge::parseFile("$this->sandboxInstance/docroot/sites/$this->site2Dir/blt.yml"); - $this->assertEquals("$this->site2Dir.local", $site2_blt_yml['drush']['aliases']['local']); + $this->assertEquals("self", $site2_blt_yml['drush']['aliases']['local']); $this->assertEquals("$this->site2Dir.clone", $site2_blt_yml['drush']['aliases']['remote']); // Clone.