Skip to content

Commit

Permalink
Merge pull request #636 from KeyboardCowboy/339-alias-sitesphp
Browse files Browse the repository at this point in the history
Fixing alias site directory lookup to check sites.php
  • Loading branch information
weitzman committed May 22, 2014
2 parents 2a7195a + 6df76df commit 614b4ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
22 changes: 22 additions & 0 deletions includes/environment.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 8 additions & 11 deletions includes/sitealias.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1522,7 +1513,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;
}

/**
Expand Down

0 comments on commit 614b4ed

Please sign in to comment.