From 3d83a3b4219fc804766cbd956e360feb21c8316a Mon Sep 17 00:00:00 2001 From: Chris Albrecht Date: Thu, 15 May 2014 19:15:34 -0600 Subject: [PATCH 1/2] site.php fix --- includes/environment.inc | 22 ++++++++++++++++++++++ includes/sitealias.inc | 8 +++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/includes/environment.inc b/includes/environment.inc index 74220e621d..2d8ef8a3f2 100644 --- a/includes/environment.inc +++ b/includes/environment.inc @@ -272,6 +272,28 @@ function drush_site_path($path = NULL) { return $site_path; } +/** + * Lookup a site's directory via the sites.php file given a hostname. + * + * @param $hostname + * The hostname of a site. May be converted from URI. + * + * @return $dir + * The directory associated with that hostname or FALSE if not found. + */ +function drush_site_dir_lookup_from_hostname($hostname) { + $site_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); + if (file_exists($site_root . '/sites/sites.php')) { + $sites = array(); + // This will overwrite $sites with the desired mappings. + include($site_root . '/sites/sites.php'); + return isset($sites[$hostname]) ? $sites[$hostname] : FALSE; + } + else { + return FALSE; + } +} + /** * This is a copy of Drupal's conf_path function, taken from D7 and * adjusted slightly to search from the selected Drupal Root. diff --git a/includes/sitealias.inc b/includes/sitealias.inc index 66c57c5c07..e497bde11b 100644 --- a/includes/sitealias.inc +++ b/includes/sitealias.inc @@ -1522,7 +1522,13 @@ function drush_sitealias_uri_to_site_dir($uri) { // Handle absolute paths on windows $uri = str_replace(array(':/', ':\\'), array('.', '.'), $uri); } - return str_replace(array('/', ':', '\\'), array('.', '.', '.'), $uri); + + $hostname = str_replace(array('/', ':', '\\'), array('.', '.', '.'), $uri); + + // Check sites.php mappings + $site_dir = drush_site_dir_lookup_from_hostname($hostname); + + return $site_dir ? $site_dir : $hostname; } /** From 6df76dffead6b44c6e0298830aacc7078403bd72 Mon Sep 17 00:00:00 2001 From: Chris Albrecht Date: Thu, 15 May 2014 19:39:38 -0600 Subject: [PATCH 2/2] removing broken sites.php lookup --- includes/sitealias.inc | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/includes/sitealias.inc b/includes/sitealias.inc index e497bde11b..4a3946a6fb 100644 --- a/includes/sitealias.inc +++ b/includes/sitealias.inc @@ -374,16 +374,7 @@ function drush_sitealias_local_site_path($alias_record) { if (isset($alias_record['root']) && !isset($alias_record['remote-host'])) { if (isset($alias_record['uri'])) { - if (file_exists($alias_record['root'] . '/sites/sites.php')) { - $sites = array(); - include($alias_record['root'] . '/sites/sites.php'); - if (array_key_exists($alias_record['uri'], $sites)) { - $result = $alias_record['root'] . '/sites/' . $sites[$alias_record['uri']]; - } - } - if (!$result) { - $result = ($alias_record['root'] . '/sites/' . drush_sitealias_uri_to_site_dir($alias_record['uri'])); - } + $result = ($alias_record['root'] . '/sites/' . drush_sitealias_uri_to_site_dir($alias_record['uri'])); $result = realpath($result); } if (!$result) {