function _drush_bootstrap_drupal_configuration

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

Initialize and load the Drupal configuration files.

We process and store a normalized set of database credentials from the loaded configuration file, so we can validate them and access them easily in the future.

1 string reference to '_drush_bootstrap_drupal_configuration'
_drush_bootstrap_phases in includes/environment.inc
Helper function listing phases.

File

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

Code

function _drush_bootstrap_drupal_configuration() {
  global $conf, $drush_conf_override;

  drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);

  // Unset drupal error handler and restore drush's one.
  if (drush_drupal_major_version() >= 7) {
    restore_error_handler();
  }

  // Overriding the $conf array from drupal CONFIGURATION bootstrap with the
  // Overrides we collected on the loaded config files on DRUSH_BOOTSTRAP_DRUSH
  $conf = is_array($conf) && is_array($drush_conf_override) ? array_merge($conf, $drush_conf_override) : $conf;

  // Populate the DRUSH_DB_CREDENTIALS with the fields loaded from the configuration.
  $creds = array();
  switch (drush_drupal_major_version()) {
    case 5:
    case 6:
      if (!empty($GLOBALS['db_url'])) {
        $url = $GLOBALS['db_url'];
        if (is_array($url)) {
          $url = $url['default'];
        }
        $parts = parse_url($url);
        $parts += array(
          'pass' => '',
          'port' => '',
        );
        $creds['driver'] = $parts['scheme'];
        $creds['user'] = urldecode($parts['user']);
        $creds['host'] = $parts['host'];
        $creds['port'] = $parts['port'];
        $creds['pass'] = urldecode($parts['pass']);
        $creds['name'] = trim($parts['path'], '/');
      }
      break;
    case 7:
    default:
      if (!empty($GLOBALS['databases']['default']['default'])) {
        $conn = $GLOBALS['databases']['default']['default'];
        // Fill in defaults to prevent notices.
        $conn += array(
          'username' => NULL,
          'host' => NULL,
          'port' => NULL,
          'password' => NULL,
          'database' => NULL,
        );
        $creds['driver'] = $conn['driver'];
        $creds['user'] = $conn['username'];
        $creds['host'] = $conn['host'];
        $creds['port'] = $conn['port'];
        $creds['name'] = $conn['database'];
        $creds['pass'] = $conn['password'];
      }
      break;
  }

  drush_set_context('DRUSH_DB_CREDENTIALS', $creds);
}