function drush_sitealias_set_alias_context

8.0.x drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')
6.x drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')
7.x drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')
3.x drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')
4.x drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')
5.x drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')
master drush_sitealias_set_alias_context($site_alias_settings, $prefix = '')

Given a site alias record, copy selected fields from it into the drush 'alias' context. The 'alias' context has lower precedence than the 'cli' context, so values set by an alias record can be overridden by command-line parameters.


site_alias_settings: An alias record

prefix: The prefix value to affix to the beginning of every key set. For example, if this function is called once with 'source-' and again with 'destination-' prefixes, then the source database records will be stored in 'source-databases', and the destination database records will be in 'destination-databases'.

3 calls to drush_sitealias_set_alias_context()
drush_bootstrap_max_to_sitealias in includes/
Bootstrap the specified site alias. The site alias must be a valid alias to a local site.
drush_sitealias_evaluate_path in includes/
Evaluate a path from its shorthand form to a literal path usable by rsync.
_drush_sitealias_set_context_by_name in includes/
Looks up the specified alias record and calls through to drush_sitealias_set_alias_context, below.


includes/, line 1767
The site alias API.


function drush_sitealias_set_alias_context($site_alias_settings, $prefix = '') {
  $options = drush_get_context('alias');

  // There are some items that we should just skip
  $skip_list = drush_get_special_keys();
  // If 'php-options' are set in the alias, then we will force drush
  // to redispatch via the remote dispatch mechanism even if the target is localhost.
  if ((array_key_exists('php-options', $site_alias_settings) || array_key_exists('php', $site_alias_settings)) && !drush_get_context('DRUSH_BACKEND', FALSE)) {
    if (!array_key_exists('remote-host', $site_alias_settings)) {
      $site_alias_settings['remote-host'] = 'localhost';
  // If 'php-options' are not set in the alias, then skip 'remote-host'
  // and 'remote-user' if 'remote-host' is actually the local machine.
  // This prevents drush from using the remote dispatch mechanism (the command
  // is just run directly on the local machine, bootstrapping to the specified alias)
  elseif (array_key_exists('remote-host', $site_alias_settings) && drush_is_local_host($site_alias_settings['remote-host'])) {
    $skip_list[] = 'remote-host';
    $skip_list[] = 'remote-user';
  // If prefix is set, then copy from the 'prefix-' version
  // of the drush special keys ('command-specific', 'path-aliases')
  // into the ordinary version.  This will allow us to set
  // 'source-command-specific' options that will only apply when
  // the alias is used as the source option for rsync or sql-sync.
  if (!empty($prefix)) {
    $special_contexts = drush_get_special_keys();
    foreach ($special_contexts as $option_name) {
      if (array_key_exists($prefix . $option_name, $site_alias_settings)) {
        $site_alias_settings[$option_name] = array_key_exists($option_name, $site_alias_settings) ? array_merge($site_alias_settings[$option_name], $site_alias_settings[$prefix . $option_name]) : $site_alias_settings[$prefix . $option_name];
  // Transfer all options from the site alias to the drush options
  // in the 'alias' context.
  foreach ($site_alias_settings as $key => $value) {
    // Special handling for path aliases:
    if ($key == "path-aliases") {
      $path_aliases = $value;
      foreach (array('%drush-script', '%dump', '%dump-dir', '%include') as $path_key) {
        if (array_key_exists($path_key, $path_aliases)) {
          // Evaluate the path value, and substitute any path references found.
          // ex: '%dump-dir' => '%root/dumps' will store sql-dumps in the folder
          // 'dumps' in the Drupal root folder for the site.
          $evaluated_path = str_replace(array_keys($path_aliases), array_values($path_aliases), $path_aliases[$path_key]);
          $options[$prefix . substr($path_key, 1)] = $evaluated_path;
    // Special handling for command-specific
    elseif ($key == "command-specific") {
      $options[$key] = $value;
    elseif (!in_array($key, $skip_list)) {
      $options[$prefix . $key] = $value;
  drush_set_config_options('alias', $options);