function _drush_sitealias_get_record

8.0.x sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)
6.x sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)
7.x sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)
3.x sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)
4.x sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)
5.x sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)
master sitealias.inc _drush_sitealias_get_record($alias, $alias_context = NULL)

This is a continuation of drush_sitealias_get_record, above. It is not intended to be called directly.

2 calls to _drush_sitealias_get_record()
drush_sitealias_get_record in includes/sitealias.inc
Get a site alias record given an alias name or site specification.
drush_sql_sync_init in commands/sql/sync.sql.inc
Sql sync init function. Bootstrap either the source or the destination site. At least one of the sites must be local for this to work; if both sites are remote, then it clearly will not be possible to bootstrap to either of them. If both are local,…

File

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

Code

function _drush_sitealias_get_record($alias, $alias_context = NULL) {
  $alias_record = array();
  // Before we do anything else, load $alias if it needs to be loaded
  _drush_sitealias_load_alias($alias, $alias_context);

  // Check to see if the provided parameter is in fact a defined alias.
  $all_site_aliases = &drush_get_context('site-aliases');
  if (array_key_exists($alias, $all_site_aliases)) {
    $alias_record = $all_site_aliases[$alias];
  }
  // If the parameter is not an alias, then it is some form of
  // site specification (or it is nothing at all)
  else {
    if (isset($alias)) {
      // Cases 1.) - 4.):
      // We will check for a site specification if the alias has at least
      // two characters from the set '@', '/', '#'.
      if ((strpos($alias, '@') === FALSE ? 0 : 1) + ((strpos($alias, '/') === FALSE && strpos($alias, '\\') === FALSE) ? 0 : 1) + (strpos($alias, '#') === FALSE ? 0 : 1) >= 2) {
        if ((substr($alias, 0, 7) != 'http://') && !drush_is_absolute_path($alias)) {
          // Add on a scheme so that "user:pass@server" will always parse correctly
          $parsed = parse_url('http://' . $alias);
        }
        else if (drush_is_windows() && drush_is_absolute_path($alias)) {
          // On windows if alias begins with a filesystem path we must add file:// scheme to make it parse correcly
          $parsed = parse_url('file:///' . $alias);
        }
        else {
          $parsed = parse_url($alias);
        }
        // Copy various parts of the parsed URL into the appropriate records of the alias record
        foreach (array(
          'user' => 'remote-user',
          'pass' => 'remote-pass',
          'host' => 'remote-host',
          'fragment' => 'uri',
          'path' => 'root',
        ) as $url_key => $option_key) {
          if (array_key_exists($url_key, $parsed)) {
            _drush_sitealias_set_record_element($alias_record, $option_key, $parsed[$url_key]);
          }
        }
        // If the site specification has a query, also set the query items
        // in the alias record.  This allows passing db_url as part of the
        // site specification, for example.
        if (array_key_exists('query', $parsed)) {
          foreach (explode('&', $parsed['query']) as $query_arg) {
            $query_components = explode('=', $query_arg);
            _drush_sitealias_set_record_element($alias_record, urldecode($query_components[0]), urldecode($query_components[1]));
          }
        }

        // Case 3.): If the URL contains a 'host' portion but no fragment, then set the uri to the host
        // Note: We presume that 'server' is the best default for case 3; without this code, the default would
        // be whatever is set in $options['l'] on the target machine's drushrc.php settings file.
        if (array_key_exists('host', $parsed) && !array_key_exists('fragment', $parsed)) {
          $alias_record['uri'] = $parsed['host'];
        }

        // Special checking:  relative aliases embedded in a path
        $relative_alias_pos = strpos($alias_record['root'], '/@');
        if ($relative_alias_pos !== FALSE) {
          // Special checking: /path/@sites
          $base = substr($alias_record['root'], 0, $relative_alias_pos);
          $relative_alias = substr($alias_record['root'], $relative_alias_pos + 1);
          if (drush_valid_drupal_root($base) || ($relative_alias == '@sites')) {
            drush_sitealias_create_sites_alias($base);
            $alias_record = drush_sitealias_get_record($relative_alias);
          }
          else {
            $alias_record = array();
          }
        }
      }
      else {
        // Case 5.) and 6.):
        // If the alias is the name of a folder in the 'sites' directory,
        // then use it as a local site specification.
        $alias_record = _drush_sitealias_find_record_for_local_site($alias);
      }
    }
  }

  if (!empty($alias_record)) {
    if (!isset($alias_record['remote']) && !isset($alias_record['#loaded-config'])) {
      if (array_key_exists('root', $alias_record)) {
        drush_sitealias_add_to_alias_path($alias_record['root'] . '/sites/all/drush');
      }
      $alias_site_dir = drush_sitealias_local_site_path($alias_record);

      if (isset($alias_site_dir)) {
        // Add the sites folder of this site to the alias search path list
        drush_sitealias_add_to_alias_path($alias_site_dir);

        // Load the drush config file if there is one associated with this alias
        if (!isset($alias_record['config'])) {
          $alias_record['config'] = realpath($alias_site_dir . '/drushrc.php');
        }
      }
      if (isset($alias_record['config']) && file_exists($alias_record['config'])) {
        drush_load_config_file('site', $alias_record['config']);
        $alias_record['#loaded-config'] = TRUE;
      }
      unset($alias_record['config']);
    }

    // Add the static defaults
    _drush_sitealias_add_static_defaults($alias_record);

    // Cache the result with all of its calculated values
    $all_site_aliases[$alias] = $alias_record;
  }

  return $alias_record;
}