Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat site-set aliases the same way that cli-specified aliases are handled. #1902

Merged
merged 1 commit into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Treat site-set aliases the same way that cli-specified aliases are ha…
…ndled. Add an automatic un-set on errors, so that users do not get stuck if a site-local alias is set, and later cannot be found (e.g. if the user cd's out of the site root.
  • Loading branch information
greg-1-anderson committed Jan 7, 2016
commit 8bcabc9ab324bbeebc6e9e65b45afc92ccf48f05
8 changes: 8 additions & 0 deletions includes/preflight.inc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ function drush_preflight() {

// Fail if we could not find the selected site alias.
if ($target_alias && empty($alias_record)) {
// We will automatically un-set the site-set alias if it could not be found.
// Otherwise, we'd be stuck -- the user would only be able to execute Drush
// commands again after `drush @none site-set @none`, and most folks would
// have a hard time figuring that out.
$site_env = drush_sitealias_site_get();
if ($site_env == $target_alias) {
drush_sitealias_site_clear();
}
return drush_set_error('DRUSH_BOOTSTRAP_NO_ALIAS', dt("Could not find the alias !alias", array('!alias' => $target_alias)));
}

Expand Down
37 changes: 21 additions & 16 deletions includes/sitealias.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use Drush\Log\LogLevel;
*/
function drush_sitealias_check_arg_and_site_set() {
$args = drush_get_arguments();
$target_alias = FALSE;

// Test to see if the first arg is a valid alias identifier.
// If the first arguement is a well-formed identifier, but we
Expand All @@ -29,24 +30,18 @@ function drush_sitealias_check_arg_and_site_set() {
// Pop the alias off the arguments list first thing.
$target_alias = array_shift($args);
drush_set_arguments($args);
// Record the user's desired target alias name
}
else {
// If the user did not specify an alias via an argument,
// check to see if a site env was set.
$target_alias = drush_sitealias_site_get();
}

// Record the user's desired target alias name
if ($target_alias) {
drush_set_context('DRUSH_TARGET_SITE_ALIAS', $target_alias);
return $target_alias;
}
// If the user did not specify an alias via an argument,
// check to see if a site env was set. For the site env,
// we insist on being able to find the alias record, or
// we will silently ignore
$site_env = drush_sitealias_site_get();
if ($site_env) {
$site_alias_settings = drush_sitealias_get_record($site_env);
if (!empty($site_alias_settings)) {
drush_set_context('DRUSH_TARGET_SITE_ALIAS', $site_env);
return $site_env;
}
}
// Return an empty array to indicate that no site alias was specified.
return FALSE;
return $target_alias;
}

/**
Expand Down Expand Up @@ -2149,6 +2144,16 @@ function drush_sitealias_site_get() {
}
}

/**
* Un-set the currently use'd site alias.
*/
function drush_sitealias_site_clear() {
if ($filename = drush_sitealias_get_envar_filename()) {
return drush_delete_dir($filename);
}
return FALSE;
}

/**
* Returns the filename for the file that stores the DRUPAL_SITE variable.
*
Expand Down