function drush_sitealias_site_set

8.0.x sitealias.drush.inc drush_sitealias_site_set($site = '@none')
6.x sitealias.drush.inc drush_sitealias_site_set($site = '@none')
7.x sitealias.drush.inc drush_sitealias_site_set($site = '@none')
5.x sitealias.drush.inc drush_sitealias_site_set($site = '@none')
master sitealias.drush.inc drush_sitealias_site_set($site = '@none')

Set the DRUPAL_SITE variable by writing it out to a temporary file that we then source for persistent site switching.

Parameters

site: A valid site specification.

File

commands/core/sitealias.drush.inc, line 369
Site alias commands.

Code

function drush_sitealias_site_set($site = '@none') {
  if ($filename = drush_sitealias_get_envar_filename()) {
    $last_site_filename = drush_sitealias_get_envar_filename('drush-drupal-prev-site-');
    if ($site == '-') {
      if (file_exists($last_site_filename)) {
        $site = file_get_contents($last_site_filename);
      }
      else {
        $site = '@none';
      }
    }
    if (_drush_sitealias_set_context_by_name($site)) {
      if (file_exists($filename)) {
        @unlink($last_site_filename);
        @rename($filename, $last_site_filename);
      }
      $success_message = dt("Site set to !site", array('!site' => $site));
      if ($site == '@none') {
        if (drush_delete_dir($filename)) {
          drush_print($success_message);
        }
      }
      elseif (drush_mkdir(dirname($filename), TRUE)) {
        if (file_put_contents($filename, $site)) {
          drush_print($success_message);
        }
      }
    }
    else {
      drush_set_error('DRUPAL_SITE_NOT_FOUND', dt("Could not find a site definition for !site.", array('!site' => $site)));
    }
  }
}