function drush_sitealias_evaluate_path

8.0.x sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE, $os = NULL, $command_specific_prefix = '')
6.x sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE, $os = NULL, $command_specific_prefix = '')
7.x sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE, $os = NULL, $command_specific_prefix = '')
3.x sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options)
4.x sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE)
5.x sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE, $os = NULL, $command_specific_prefix = '')
master sitealias.inc drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE, $os = NULL, $command_specific_prefix = '')

Evaluate a path from its shorthand form to a literal path usable by rsync.

A path is "machine:/path" or "machine:path" or "/path" or "path". 'machine' might instead be an alias record, or the name of a site in the 'sites' folder. 'path' might be (or contain) '%root' or some other path alias. This function will examine all components of the path and evaluate them as necessary to come to the final path.

Parameters

path: The path to evaluate

additional_options: An array of options that overrides whatever was passed in on the command line (like the 'process' context, but only for the scope of this one call).

Return value

The site record for the machine specified in the path, if any, with the path to pass to rsync (including the machine specifier) in the 'evaluated-path' item.

2 calls to drush_sitealias_evaluate_path()
drush_core_rsync in commands/core/rsync.core.inc
Entrypoint for drush rsync.
_drush_core_directory in commands/core/core.drush.inc
Given a target (e.g. @site:%modules), return the evaluated directory path

File

includes/sitealias.inc, line 1461
The site alias API.

Code

function drush_sitealias_evaluate_path($path, &$additional_options, $local_only = FALSE) {
  $site_alias_settings = array();
  $path_aliases = array();
  $remote_user = '';

  $preflight = _drush_sitealias_preflight_path($path);
  if (!isset($preflight)) {
    return NULL;
  }

  $alias = $preflight['alias'];
  $path = $preflight['path'];
  $machine = $preflight['machine'];

  if (isset($alias)) {
    $site_alias_settings = drush_sitealias_get_record($alias);
  }

  if (!empty($site_alias_settings)) {
    if ($local_only && array_key_exists('remote-host', $site_alias_settings)) {
      return drush_set_error('DRUSH_REMOTE_SITE_IN_LOCAL_CONTEXT', dt("A remote site alias was used in a context where only a local alias is appropriate."));
    }

    // Apply any options from this alias that might affect our rsync
    drush_sitealias_set_alias_context($site_alias_settings);

    // Use 'remote-host' from settings if available; otherwise site is local
    if (array_key_exists('remote-host', $site_alias_settings) && !drush_is_local_host($site_alias_settings['remote-host'])) {
      if (array_key_exists('remote-user', $site_alias_settings)) {
        $remote_user = $site_alias_settings['remote-user'] . '@';
      }
      $machine = $remote_user . $site_alias_settings['remote-host'];
    }
    else {
      $machine = '';
    }
  }
  else {
    // Strip the machine portion of the path if the
    // alias points to the local machine.
    if (drush_is_local_host($machine)) {
      $machine = '';
    }
    else {
      $machine = "$remote_user$machine";
    }
  }

  // If the --exclude-other-sites option is specified, then
  // convert that into --include-path='%site' and --exclude-sites.
  if (drush_get_option_override($additional_options, 'exclude-other-sites', FALSE) && !drush_get_option_override($additional_options, 'exclude-other-sites-processed', FALSE, 'process')) {
    $additional_options['include-path'] = '%site,' . drush_get_option_override($additional_options, 'include-path', '');
    $additional_options['exclude-sites'] = TRUE;
    $additional_options['exclude-other-sites-processed'] = TRUE;
  }
  // If the --exclude-files option is specified, then
  // convert that into --exclude-path='%files'.
  if (drush_get_option_override($additional_options, 'exclude-files', FALSE) && !drush_get_option_override($additional_options, 'exclude-files-processed', FALSE, 'process')) {
    $additional_options['exclude-path'] = '%files,' . drush_get_option_override($additional_options, 'exclude-path', '');
    $additional_options['exclude-files-processed'] = TRUE;
  }

  // If there was no site specification given, and the
  // machine is local, then try to look
  // up an alias record for the default drush site.
  if (empty($site_alias_settings) && empty($machine)) {
    $drush_uri = drush_bootstrap_value('drush_uri', drush_get_option(array('l', 'uri'), 'default'));
    $site_alias_settings = drush_sitealias_get_record($drush_uri);
  }

  // Always add transient defaults
  _drush_sitealias_add_transient_defaults($site_alias_settings);

  // The $resolve_path variable is used by drush_sitealias_resolve_path_references
  // to test to see if there are any path references such as %site or %files
  // in it, so that resolution is only done if the path alias is referenced.
  // Therefore, we can concatenate without worrying too much about the structure of
  // this variable's contents.
  $include_path = drush_get_option_override($additional_options, 'include-path', '');
  $exclude_path = drush_get_option_override($additional_options, 'exclude-path', '');
  $resolve_path = $path . $include_path . $exclude_path;
  // Resolve path aliases such as %files, if any exist in the path
  if (!empty($resolve_path)) {
    drush_sitealias_resolve_path_references($site_alias_settings, $resolve_path);
  }

  if (array_key_exists('path-aliases', $site_alias_settings)) {
    $path_aliases = $site_alias_settings['path-aliases'];
  }

  // Get the 'root' setting from the alias; if it does not
  // exist, then get the root from the bootstrapped site.
  if (array_key_exists('root', $site_alias_settings)) {
    $drupal_root = $site_alias_settings['root'];
  }
  else {
    drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_SITE);
    $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
  }
  if (empty($drupal_root)) {
    $drupal_root = '';
  }
  // Add a slash to the end of the drupal root, as below.
  elseif ($drupal_root[strlen($drupal_root) -1] != '/') {
    $drupal_root = $drupal_root . '/';
  }
  $full_path_aliases = $path_aliases;
  foreach ($full_path_aliases as $key => $value) {
    // Expand all relative path aliases to be based off of the Drupal root
    if ((substr($value, 0, 1) != '/') && ($key != '%root')) {
      $full_path_aliases[$key] = $drupal_root . $value;
    }
    // We do not want slashes on the end of our path aliases.
    if (substr($value, 0, -1) == '/') {
      $full_path_aliases[$key] = substr($full_path_aliases[$key], -1);
    }
  }

  // Fill in path aliases in the path, the include path and the exclude path.
  $path = str_replace(array_keys($full_path_aliases), array_values($full_path_aliases), $path);
  if (!empty($include_path)) {
    drush_set_option('include-path', str_replace(array_keys($path_aliases), array_values($path_aliases), $include_path));
  }
  if (!empty($exclude_path)) {
    drush_set_option('exclude-path', str_replace(array_keys($path_aliases), array_values($path_aliases), $exclude_path));
  }

  // The path component is just the path part of the full
  // machine:path specification (including the colon).
  $path_component = (!empty($path) ? ':' . $path : '');

  // Next make the rsync path, which includes the machine
  // and path components together.
  // First make empty paths or relative paths start from the drupal root.
  if (empty($path) || ($path[0] != '/')) {
    $path = $drupal_root . $path;
  }

  // If there is a $machine component, to the path, then
  // add it to the beginning
  $evaluated_path = $path;
  if (!empty($machine)) {
    $evaluated_path = $machine . ':' . $path;
  }

  //
  // Add our result paths:
  //
  //    evaluated-path:         machine:/path
  //    server-component:       machine
  //    path-component:         :/path
  //    path:                   /path
  //    user-path:              path (as specified in input parameter)
  //
  $site_alias_settings['evaluated-path'] = $evaluated_path;
  if (!empty($machine)) {
    $site_alias_settings['server-component'] = $machine;
  }
  $site_alias_settings['path-component'] = $path_component;
  $site_alias_settings['path'] = $path;
  $site_alias_settings['user-path'] = $preflight['path'];

  return $site_alias_settings;
}