function install_begin_request

Begins an installation request, modifying the installation state as needed.

This function performs commands that must run at the beginning of every page request. It throws an exception if the installation should not proceed.

Parameters

$install_state: An array of information about the current installation state. This is modified with information gleaned from the beginning of the page request.

1 call to install_begin_request()
install_drupal in drupal/core/includes/install.core.inc
Installs Drupal either interactively or via an array of passed-in settings.

File

drupal/core/includes/install.core.inc, line 235
API functions for installing Drupal.

Code

function install_begin_request(&$install_state) {

  // Add any installation parameters passed in via the URL.
  if ($install_state['interactive']) {
    $install_state['parameters'] += $_GET;
  }

  // Validate certain core settings that are used throughout the installation.
  if (!empty($install_state['parameters']['profile'])) {
    $install_state['parameters']['profile'] = preg_replace('/[^a-zA-Z_0-9]/', '', $install_state['parameters']['profile']);
  }
  if (!empty($install_state['parameters']['langcode'])) {
    $install_state['parameters']['langcode'] = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $install_state['parameters']['langcode']);
  }

  // Allow command line scripts to override server variables used by Drupal.
  require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
  if (!$install_state['interactive']) {
    drupal_override_server_variables($install_state['server']);
  }
  elseif (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
    exit;
  }

  // Initialize conf_path().
  // This primes the site path to be used during installation. By not requiring
  // settings.php, a bare site folder can be prepared in the /sites directory,
  // which will be used for installing Drupal.
  conf_path(FALSE);
  drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);

  // A request object from the HTTPFoundation to tell us about the request.
  $request = Request::createFromGlobals();

  // This must go after drupal_bootstrap(), which unsets globals!
  global $conf;
  require_once DRUPAL_ROOT . '/core/modules/system/system.install';
  require_once DRUPAL_ROOT . '/core/includes/common.inc';
  require_once DRUPAL_ROOT . '/core/includes/file.inc';
  require_once DRUPAL_ROOT . '/core/includes/install.inc';
  require_once DRUPAL_ROOT . '/core/includes/schema.inc';
  require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'core/includes/path.inc');

  // Load module basics (needed for hook invokes).
  include_once DRUPAL_ROOT . '/core/includes/module.inc';
  include_once DRUPAL_ROOT . '/core/includes/session.inc';
  require_once DRUPAL_ROOT . '/core/includes/entity.inc';

  // Determine whether the configuration system is ready to operate.
  $install_state['config_verified'] = install_verify_config_directory(CONFIG_ACTIVE_DIRECTORY) && install_verify_config_directory(CONFIG_STAGING_DIRECTORY);

  // Check existing settings.php.
  $install_state['database_verified'] = install_verify_database_settings();
  $install_state['settings_verified'] = $install_state['config_verified'] && $install_state['database_verified'];

  // If it is not, replace the configuration storage with the InstallStorage
  // implementation, for the following reasons:
  // - The first call into drupal_container() will try to set up the regular
  //   runtime configuration storage, using the CachedStorage by default. It
  //   calls config_get_config_directory() to retrieve the config directory to
  //   use, but that throws an exception, since $config_directories is not
  //   defined since there is no settings.php yet. If there is a prepared
  //   settings.php already, then the returned directory still cannot be used,
  //   because it does not necessarily exist. The installer ensures that it
  //   exists and is writeable in a later step.
  // - The installer outputs maintenance theme pages and performs many other
  //   operations, which try to load configuration. Since there is no active
  //   configuration yet, and because the configuration system does not have a
  //   notion of default values at runtime, data is missing in many places. The
  //   lack of data does not trigger errors, but results in a broken user
  //   interface (e.g., missing page title, etc).
  // - The actual configuration data to read during installation is essentially
  //   the default configuration provided by the installation profile and
  //   modules (most notably System module). The InstallStorage therefore reads
  //   from the default configuration directories of extensions.
  // This override is reverted as soon as the config directory and the
  // database has been set up successfully.
  // @see drupal_install_config_directories()
  // @see install_settings_form_submit()
  if ($install_state['settings_verified']) {
    $kernel = new DrupalKernel('install', FALSE, drupal_classloader(), FALSE);
    $kernel
      ->boot();
  }
  else {

    // @todo Move into a proper Drupal\Core\DependencyInjection\InstallContainerBuilder.
    $container = new ContainerBuilder();
    $container
      ->register('dispatcher', 'Symfony\\Component\\EventDispatcher\\EventDispatcher');
    $container
      ->register('config.storage', 'Drupal\\Core\\Config\\InstallStorage');
    $container
      ->register('config.factory', 'Drupal\\Core\\Config\\ConfigFactory')
      ->addArgument(new Reference('config.storage'))
      ->addArgument(new Reference('dispatcher'));
    drupal_container($container);
  }

  // Set up $language, so t() caller functions will still work.
  drupal_language_initialize();
  require_once DRUPAL_ROOT . '/core/includes/ajax.inc';

  // Override the module list with a minimal set of modules.
  $module_list['system']['filename'] = 'core/modules/system/system.module';
  module_list(NULL, $module_list);
  drupal_load('module', 'system');

  // Load the cache infrastructure using a "fake" cache implementation that
  // does not attempt to write to the database. We need this during the initial
  // part of the installer because the database is not available yet. We
  // continue to use it even when the database does become available, in order
  // to preserve consistency between interactive and command-line installations
  // (the latter complete in one page request and therefore are forced to
  // continue using the cache implementation they started with) and also
  // because any data put in the cache during the installer is inherently
  // suspect, due to the fact that Drupal is not fully set up yet.
  require_once DRUPAL_ROOT . '/core/includes/cache.inc';
  $conf['cache_classes'] = array(
    'cache' => 'Drupal\\Core\\Cache\\InstallBackend',
  );

  // The install process cannot use the database lock backend since the database
  // is not fully up, so we use a null backend implementation during the
  // installation process. This will also speed up the installation process.
  // The site being installed will use the real lock backend when doing AJAX
  // requests but, except for a WSOD, there is no chance for a a lock to stall
  // (as opposed to the cache backend) so we can afford having a null
  // implementation here.
  $conf['lock_backend'] = 'Drupal\\Core\\Lock\\NullLockBackend';

  // Prepare for themed output. We need to run this at the beginning of the
  // page request to avoid a different theme accidentally getting set. (We also
  // need to run it even in the case of command-line installations, to prevent
  // any code in the installer that happens to initialize the theme system from
  // accessing the database before it is set up yet.)
  drupal_maintenance_theme();
  if ($install_state['database_verified']) {

    // Initialize the database system. Note that the connection
    // won't be initialized until it is actually requested.
    require_once DRUPAL_ROOT . '/core/includes/database.inc';

    // Verify the last completed task in the database, if there is one.
    $task = install_verify_completed_task();
  }
  else {
    $task = NULL;

    // Do not install over a configured settings.php. Check the 'db_url'
    // variable in addition to 'databases', since previous versions of Drupal
    // used that (and we do not want to allow installations on an existing site
    // whose settings file has not yet been updated).
    if (!empty($GLOBALS['databases']) || !empty($GLOBALS['db_url'])) {
      throw new Exception(install_already_done_error());
    }
  }

  // Modify the installation state as appropriate.
  $install_state['completed_task'] = $task;
  $install_state['database_tables_exist'] = !empty($task);

  // Add the list of available profiles to the installation state.
  $install_state['profiles'] += drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\\.profile$/', 'profiles');
}