install_drupal

install_drupal($class_loader, $settings = array())

Installs Drupal either interactively or via an array of passed-in settings.

The Drupal installation happens in a series of steps, which may be spread out over multiple page requests. Each request begins by trying to determine the last completed installation step (also known as a "task"), if one is available from a previous request. Control is then passed to the task handler, which processes the remaining tasks that need to be run until (a) an error is thrown, (b) a new page needs to be displayed, or (c) the installation finishes (whichever happens first).

Parameters

$class_loader: The class loader. Normally Composer's ClassLoader, as included by the front controller, but may also be decorated; e.g., \Symfony\Component\ClassLoader\ApcClassLoader.

$settings: An optional array of installation settings. Leave this empty for a normal, interactive, browser-based installation intended to occur over multiple page requests. Alternatively, if an array of settings is passed in, the installer will attempt to use it to perform the installation in a single page request (optimized for the command line) and not send any output intended for the web browser. See install_state_defaults() for a list of elements that are allowed to appear in this array.

See also

install_state_defaults()

File

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

Code

function install_drupal($class_loader, $settings = array()) {
  // Support the old way of calling this function with just a settings array.
  // @todo Remove this when Drush is updated in the Drupal testing
  //   infrastructure in https://www.drupal.org/node/2389243
  if (is_array($class_loader) && $settings === array()) {
    $settings = $class_loader;
    $class_loader = require __DIR__ . '/../../autoload.php';
  }

  global $install_state;
  // Initialize the installation state with the settings that were passed in,
  // as well as a boolean indicating whether or not this is an interactive
  // installation.
  $interactive = empty($settings);
  $install_state = $settings + array('interactive' => $interactive) + install_state_defaults();

  try {
    // Begin the page request. This adds information about the current state of
    // the Drupal installation to the passed-in array.
    install_begin_request($class_loader, $install_state);
    // Based on the installation state, run the remaining tasks for this page
    // request, and collect any output.
    $output = install_run_tasks($install_state);
  }
  catch (InstallerException $e) {
    // In the non-interactive installer, exceptions are always thrown directly.
    if (!$install_state['interactive']) {
      throw $e;
    }
    $output = array(
      '#title' => $e->getTitle(),
      '#markup' => $e->getMessage(),
    );
  }

  // After execution, all tasks might be complete, in which case
  // $install_state['installation_finished'] is TRUE. In case the last task
  // has been processed, remove the global $install_state, so other code can
  // reliably check whether it is running during the installer.
  // @see drupal_installation_attempted()
  $state = $install_state;
  if (!empty($install_state['installation_finished'])) {
    unset($GLOBALS['install_state']);
  }

  // All available tasks for this page request are now complete. Interactive
  // installations can send output to the browser or redirect the user to the
  // next page.
  if ($state['interactive']) {
    // If a session has been initiated in this request, make sure to save it.
    if ($session = \Drupal::request()->getSession()) {
      $session->save();
    }
    if ($state['parameters_changed']) {
      // Redirect to the correct page if the URL parameters have changed.
      install_goto(install_redirect_url($state));
    }
    elseif (isset($output)) {
      // Display a page only if some output is available. Otherwise it is
      // possible that we are printing a JSON page and theme output should
      // not be shown.
      install_display_output($output, $state);
    }
    elseif ($state['installation_finished']) {
      // Redirect to the newly installed site.
      install_goto('');
    }
  }
}
doc_Drupal
2016-10-29 09:21:00
Comments
Leave a Comment

Please login to continue.