function _drush_bootstrap_drupal_site_validate

6.x bootstrap.inc _drush_bootstrap_drupal_site_validate()
3.x environment.inc _drush_bootstrap_drupal_site_validate()
4.x environment.inc _drush_bootstrap_drupal_site_validate()
5.x bootstrap.inc _drush_bootstrap_drupal_site_validate()

VALIDATE the DRUSH_BOOTSTRAP_DRUPAL_SITE phase.

In this function we determine the URL used for the command, and check for a valid settings.php file.

To do this, we need to set up the $_SERVER environment variable, to allow us to use conf_path to determine what Drupal will load as a configuration file.

1 call to _drush_bootstrap_drupal_site_validate()
_drush_bootstrap_redo_drupal_site in includes/environment.inc
Re-do the drupal site bootstrap (and possibly the drupal root bootstrap) if a site alias was processed after the site bootstrap phase completed. This will happen when processing "drush sitealias command" for a site alias defined in a…

File

includes/environment.inc, line 764
Functions used by drush to query the environment and setting the current configuration.

Code

function _drush_bootstrap_drupal_site_validate() {
  $site_path = drush_site_path();
  $elements = explode('/', $site_path);
  $current = array_pop($elements);
  if (!$current) {
    $current = 'default';
  }
  $uri = 'http://' . $current;

  $drush_uri = drush_bootstrap_value('drush_uri', drush_get_option(array('l', 'uri'), $uri));

  // Fake the necessary HTTP headers that Drupal needs:
  if ($drush_uri) {
    $drupal_base_url = parse_url($drush_uri);
    // If there's no url scheme set, add http:// and re-parse the url
    // so the host and path values are set accurately.
    if (!array_key_exists('scheme', $drupal_base_url)) {
      $drush_uri = 'http://' . $drush_uri;
      $drupal_base_url = parse_url($drush_uri);
    }
    // Fill in defaults.
    $drupal_base_url += array(
      'path' => NULL,
      'host' => NULL,
      'port' => NULL,
    );
    $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];

    if ($drupal_base_url['port']) {
      $_SERVER['HTTP_HOST'] .= ':' . $drupal_base_url['port'];
    }
    $_SERVER['SERVER_PORT'] = $drupal_base_url['port'];

    if (array_key_exists('path', $drupal_base_url)) {
      $_SERVER['PHP_SELF'] = $drupal_base_url['path'] . '/index.php';
    }
    else {
      $_SERVER['PHP_SELF'] = '/index.php';
    }
  }
  else {
    $_SERVER['HTTP_HOST'] = 'default';
    $_SERVER['PHP_SELF'] = '/index.php';
  }

  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  $_SERVER['REQUEST_METHOD'] = NULL;

  $_SERVER['SERVER_SOFTWARE'] = NULL;
  $_SERVER['HTTP_USER_AGENT'] = NULL;

  $site = drush_bootstrap_value('site', $_SERVER['HTTP_HOST']);

  $conf_path = drush_bootstrap_value('conf_path', conf_path(TRUE, TRUE));
  $conf_file = "./$conf_path/settings.php";
  if (!file_exists($conf_file)) {
    return drush_bootstrap_error('DRUPAL_SITE_SETTINGS_NOT_FOUND', dt("Could not find a Drupal settings.php file at !file.", array('!file' => $conf_file)));
  }

  return TRUE;
}