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.

Also override Drupal variables as per --variables option.

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

File

includes/bootstrap.inc, line 839
Drush bootstrapping code.

Code

function _drush_bootstrap_drupal_configuration() {
  global $conf;

  drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);

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

  $override = array(
    'dev_query' => FALSE, // Force Drupal6 not to store queries since we are not outputting them.
    'cron_safe_threshold' => 0, // Don't run poormanscron during Drush request (D7+).
  );
  // Avoid MTimeProtected grief in D8+. See http://drupal.org/node/1899842. If you really don't
  // want this override, set different values using a drushrc.php by passing different values.
  $override['php_storage']['default'] = array(
    'class' => 'Drupal\Component\PhpStorage\FileReadOnlyStorage',
    // 'directory' => drush_directory_cache('php_storage'),
  );

  $current_override = drush_get_option_list('variables');
  foreach ($current_override as $name => $value) {
    if (is_numeric($name) && (strpos($value, '=') !== FALSE)) {
      list($name, $value) = explode('=', $value, 2);
    }
    $override[$name] = $value;
  }
  $conf = is_array($conf) ? array_merge($conf, $override) : $conf;

  // Populate the DRUSH_DB_CREDENTIALS with the fields loaded from the configuration.
  $creds = array();
  switch (drush_drupal_major_version()) {
    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,
          'unix_socket' => NULL,
        );
        $creds['driver'] = $conn['driver'];
        $creds['user'] = $conn['username'];
        $creds['unix_socket'] = $conn['unix_socket'];
        $creds['host'] = $conn['host'];
        $creds['port'] = $conn['port'];
        $creds['name'] = $conn['database'];
        $creds['pass'] = $conn['password'];
        if (isset($conn['pdo'])) {
          $creds['pdo'] = $conn['pdo'];
        }
        else {
          $creds['pdo'] = null;
        }
      }
      break;
  }

  drush_set_context('DRUSH_DB_CREDENTIALS', $creds);
}