install_8.inc

Rebuild all the caches

Functions

Constants

Namesort descending Description
MAINTENANCE_MODE

File

platform/drupal/install_8.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Rebuild all the caches
  5. */
  6. use Drupal\Core\Url;
  7. $GLOBALS['url'] = d()->uri;
  8. $GLOBALS['profile'] = d()->profile;
  9. $GLOBALS['install_locale'] = d()->language;
  10. $GLOBALS['base_url'] = provision_get_base_url();
  11. define('MAINTENANCE_MODE', 'install');
  12. function install_send_welcome_mail($url, $account, $language, $client_email, $onetime) {
  13. global $base_url;
  14. if ($client_email) {
  15. // Mail one time login URL and instructions.
  16. $from = \Drupal::config('system.site')->get('mail');
  17. $username = $account->getUsername();
  18. $site = \Drupal::config('system.site')->get('name');
  19. $uri_brief = preg_replace('!^https?://!', '', $base_url);
  20. $edit_uri = $base_url . '/user/1/edit';
  21. $mailto = $account->getEmail();
  22. $date = format_date(time());
  23. $mail_params['variables'] = array(
  24. '!username' => $username,
  25. '!site' => $site,
  26. '!login_url' => $onetime,
  27. '!uri' => $base_url,
  28. '!uri_brief' => $uri_brief,
  29. '!edit_uri' => $edit_uri,
  30. '!mailto' => $mailto,
  31. '!date' => $date,
  32. );
  33. $langcode = $account->getPreferredLangcode();
  34. $mail_success = \Drupal::service('plugin.manager.mail')->mail('install', 'welcome-admin', $mailto, $langcode, $mail_params, $from, TRUE);
  35. if ($mail_success) {
  36. drush_log(dt('Sent welcome mail to @client', array('@client' => $client_email)), 'message');
  37. }
  38. else {
  39. drush_log(dt('Could not send welcome mail to @client', array('@client' => $client_email)));
  40. }
  41. }
  42. }
  43. function install_mail($key, &$message, $params) {
  44. global $profile;
  45. switch ($key) {
  46. case 'welcome-admin':
  47. // allow the profile to override welcome email text
  48. if (file_exists("./profiles/$profile/provision_welcome_mail.inc")) {
  49. require_once "./profiles/$profile/provision_welcome_mail.inc";
  50. $custom = TRUE;
  51. }
  52. elseif (file_exists(dirname(__FILE__) . '/../provision_welcome_mail.inc')) {
  53. /** use the module provided welcome email
  54. * We can not use drupal_get_path here,
  55. * as we are connected to the provisioned site's database
  56. */
  57. require_once dirname(__FILE__) . '/../provision_welcome_mail.inc';
  58. $custom = TRUE;
  59. }
  60. else {
  61. // last resort use the user-pass mail text
  62. $custom = FALSE;
  63. }
  64. if ($custom) {
  65. $message['subject'] = dt($mail['subject'], $params['variables']);
  66. $message['body'][] = dt($mail['body'], $params['variables']);
  67. }
  68. else {
  69. $message['subject'] = _user_mail_text('pass_subject', $params['variables']);
  70. $message['body'][] = _user_mail_text('pass_body', $params['variables']);
  71. }
  72. break;
  73. }
  74. }
  75. function install_main() {
  76. global $profile, $install_locale, $conf, $url, $base_url;
  77. $client_email = drush_get_option('client_email');
  78. require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
  79. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
  80. // We have an existing settings.php.
  81. require_once DRUSH_BASE_PATH . '/commands/sql/sql.drush.inc';
  82. $sql = drush_sql_get_class();
  83. $db_spec = $sql->db_spec();
  84. $db_spec['db_prefix'] = $GLOBALS['db_prefix'];
  85. if ($db_spec['driver'] == 'mysqli') {
  86. $db_spec['driver'] = 'mysql';
  87. }
  88. unset($config['site_name']);
  89. unset($config['site_mail']);
  90. unset($GLOBALS['db_url']);
  91. $account_pass = provision_password();
  92. $settings = array(
  93. 'parameters' => array(
  94. 'profile' => $profile,
  95. 'locale' => $install_locale,
  96. ),
  97. 'settings_verified' => TRUE,
  98. 'forms' => array(
  99. 'install_settings_form' => $db_spec,
  100. 'install_configure_form' => array(
  101. 'site_name' => $url,
  102. 'site_mail' => $client_email ? $client_email : 'admin@example.com',
  103. 'account' => array(
  104. 'name' => 'admin',
  105. 'mail' => $client_email ? $client_email : 'admin@example.com',
  106. 'pass' => array(
  107. 'pass1' => $account_pass,
  108. 'pass2' => $account_pass,
  109. ),
  110. ),
  111. 'update_status_module' => array(
  112. 1 => TRUE,
  113. 2 => TRUE,
  114. ),
  115. 'clean_url' => drush_get_option('clean_url', TRUE),
  116. ),
  117. ),
  118. );
  119. try {
  120. install_drupal($settings);
  121. }
  122. catch (Exception $e) {
  123. drush_set_error('DRUPAL_INSTALL_FAILED');
  124. dlm($e);
  125. }
  126. _provision_drupal_create_directories();
  127. // Set files paths
  128. \Drupal::configFactory()->getEditable('system.file')
  129. ->set('path.private', "sites/$url/private/files")
  130. ->set('path.temporary', "sites/$url/private/temp")
  131. ->save();
  132. $account = user_load(1);
  133. $onetime = user_pass_reset_url($account);
  134. // Store the one time login link in an option so the front end can direct the user to their new site.
  135. drush_set_option('login_link', $onetime);
  136. drush_log(dt('Login url: !onetime', array('!onetime' => $onetime)), 'message');
  137. if ($client_email) {
  138. install_send_welcome_mail($url, $account, $install_locale, $client_email, $onetime);
  139. }
  140. }
  141. install_main();
  142. function install_exception_handler() {
  143. dlm(func_get_args());
  144. }