function _drush_sitealias_derive_record

8.0.x sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
6.x sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
7.x sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
3.x sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
4.x sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
5.x sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
master sitealias.inc _drush_sitealias_derive_record($from_record, $modifying_record)
1 call to _drush_sitealias_derive_record()
_drush_sitealias_initialize_alias_record in includes/sitealias.inc
Initialize an alias record; called as soon as the alias record is loaded from its alias file, before it is stored in the cache.

File

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

Code

function _drush_sitealias_derive_record($from_record, $modifying_record) {
  $result = $from_record;

  // If there is a 'remote-user' in the modifying record, copy it.
  if (array_key_exists('remote-user', $modifying_record)) {
    $result['remote-user'] = $from_record['remote_user'];
  }
  // If there is a 'remote-host', then:
  //   If it is empty, clear the remote host in the result record
  //   If it ends in '.', then prepend it to the remote host in the result record
  //   Otherwise, copy it to the result record
  if (array_key_exists('remote-host', $modifying_record)) {
    $remote_host_modifier = $modifying_record['remote-host'];
    if (empty($remote_host_modifier)) {
      unset($result['remote-host']);
      unset($result['remote-user']);
    }
    elseif ($remote_host_modifier[strlen($remote_host_modifier) -1] == '.') {
      $result['remote-host'] = $remote_host_modifier . $result['remote-host'];
    }
    else {
      $result['remote-host'] = $remote_host_modifier;
    }
  }
  // If there is a 'root', then:
  //   If it begins with '/', copy it to the result record
  //   Otherwise, append it to the result record
  if (array_key_exists('root', $modifying_record)) {
    $root_modifier = $modifying_record['root'];
    if ($root_modifier[0] == '/') {
      $result['root'] = $root_modifier;
    }
    else {
      $result['root'] = $result['root'] . '/' . $root_modifier;
    }
  }
  // Poor man's realpath: take out the /../ with preg_replace.
  // (realpath fails if the files in the path do not exist)
  while (strpos($result['root'], '/../') !== FALSE) {
    $result['root'] = preg_replace('/\w+\/\.\.\//', '', $result['root']);
  }

  // TODO:  Should we allow the uri to be transformed?
  // I think that if the uri does not match, then you should
  // always build the list by hand, and not rely on '_drush_sitealias_derive_record'.

  return $result;
}