Skip to content

Commit

Permalink
Multisite bugfixes (acquia#3231)
Browse files Browse the repository at this point in the history
* 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..
  • Loading branch information
lcatlett authored and grasmash committed Dec 17, 2018
1 parent a416e19 commit 27cbc7a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 37 deletions.
37 changes: 12 additions & 25 deletions scripts/factory-hooks/post-install/post-install.php
Expand Up @@ -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);

/**
Expand All @@ -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();
Expand All @@ -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),
Expand All @@ -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)));
Expand All @@ -101,5 +90,3 @@ function error($message) {
fwrite(STDERR, "Command execution returned status code: $result!\n");
exit($result);
}


8 changes: 3 additions & 5 deletions scripts/factory-hooks/post-settings-php/memcache.php
Expand Up @@ -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';
}


10 changes: 7 additions & 3 deletions scripts/factory-hooks/post-sites-php/includes.php
@@ -1,12 +1,15 @@
<?php

/**
* @file
* Example implementation of ACSF post-sites-php hook.
*
* @see https://docs.acquia.com/site-factory/tiers/paas/workflow/hooks
*/

// The function_exists check is required as the file is included several times.
if (!function_exists('gardens_data_get_sites_from_file')) {

/**
* Get the domains defined for the given site.
*
Expand All @@ -32,7 +35,7 @@ function gardens_data_get_sites_from_file($name, $reset = FALSE) {
elseif ($map = gardens_site_data_load_file()) {
$domains = array_filter(
$map['sites'],
function($item) use ($name) {
function ($item) use ($name) {
return $item['name'] == $name;
}
);
Expand All @@ -46,9 +49,10 @@ function($item) use ($name) {
}
return $domains;
}

}
// Get all the domains that are defined for the current site.
$domains = gardens_data_get_sites_from_file($data['gardens_site_settings']['conf']['acsf_db_name']);
// Get the site's name from the first domain.
global $acsf_site_name;
$acsf_site_name = explode('.', array_keys($domains)[0])[0];
global $_acsf_site_name;
$_acsf_site_name = explode('.', array_keys($domains)[0])[0];
2 changes: 1 addition & 1 deletion settings/blt.settings.php
Expand Up @@ -151,7 +151,7 @@
$name = array_slice($domain_fragments, 1);
$acsf_sites = $blt_config->get('multisites');
if (in_array($name, $acsf_sites)) {
$acsf_site_name = $name;
$_acsf_site_name = $name;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings/config.settings.php
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Robo/Commands/Generate/MultisiteCommand.php
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Blt/MultiSiteTest.php
Expand Up @@ -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.
Expand Down

0 comments on commit 27cbc7a

Please sign in to comment.