1.20.x install.core.inc install_begin_request(&$install_state)

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.

Throws

Exception

File

includes/install.core.inc, line 213
API functions for installing Backdrop.

Code

function install_begin_request(&$install_state) {
  // Add any installation parameters passed in via the URL.
  $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 Backdrop.
  require_once BACKDROP_ROOT . '/core/includes/bootstrap.inc';
  if (!$install_state['interactive']) {
    backdrop_override_server_variables($install_state['server']);
  }

  // The user agent header is used to pass a database prefix in the request when
  // running tests. However, for security reasons, it is imperative that no
  // installation be permitted using such a prefix.
  if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
    exit;
  }

  backdrop_bootstrap(BACKDROP_BOOTSTRAP_CONFIGURATION);

  require_once BACKDROP_ROOT . '/core/modules/system/system.install';
  require_once BACKDROP_ROOT . '/core/includes/common.inc';
  require_once BACKDROP_ROOT . '/core/includes/file.inc';
  require_once BACKDROP_ROOT . '/core/includes/install.inc';
  require_once BACKDROP_ROOT . '/' . settings_get('path_inc', 'core/includes/path.inc');

  // Load module basics (needed for hook invokes).
  include_once BACKDROP_ROOT . '/core/includes/module.inc';
  include_once BACKDROP_ROOT . '/core/includes/session.inc';
  require_once BACKDROP_ROOT . '/core/includes/theme.inc';
  require_once BACKDROP_ROOT . '/core/includes/tablesort.inc';

  require_once BACKDROP_ROOT . '/core/includes/ajax.inc';
  $module_list['system']['filename'] = 'core/modules/system/system.module';
  $module_list['entity']['filename'] = 'core/modules/entity/entity.module';
  $module_list['user']['filename'] = 'core/modules/user/user.module';
  module_list(TRUE, FALSE, FALSE, $module_list);
  backdrop_load('module', 'system');
  backdrop_load('module', 'entity');
  backdrop_load('module', 'user');

  // 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 Backdrop is not fully set up yet.
  require_once BACKDROP_ROOT . '/core/includes/cache.inc';
  backdrop_load_backends('cache');
  require_once BACKDROP_ROOT . '/core/includes/cache-install.inc';
  $GLOBALS['settings']['cache_default_class'] = 'BackdropFakeCache';

  // Set up $language, so t() caller functions will still work.
  backdrop_language_initialize();

  // 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.)
  backdrop_maintenance_theme();

  // Check existing settings.php.
  $install_state['settings_verified'] = install_verify_settings();

  if ($install_state['settings_verified']) {
    // Initialize the database system. Note that the connection
    // won't be initialized until it is actually requested.
    require_once BACKDROP_ROOT . '/core/includes/database/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.
    if (!empty($GLOBALS['databases'])) {
      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'] += install_find_profiles();
}