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
File
- core/includes/install.core.inc, line 93
- API functions for installing Drupal.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 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( '' ); } } } |
Please login to continue.