install_7.inc

Rebuild all the caches

Functions

Constants

Namesort descending Description
MAINTENANCE_MODE

File

platform/drupal/install_7.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Rebuild all the caches
  5. */
  6. $GLOBALS['url'] = d()->uri;
  7. $GLOBALS['profile'] = d()->profile;
  8. $GLOBALS['install_locale'] = d()->language;
  9. $GLOBALS['base_url'] = provision_get_base_url();
  10. require_once 'install.inc'; // From Provision, not the Drupal platform.
  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 = variable_get('site_mail', ini_get('sendmail_from'));
  17. $mail_params['variables'] = array(
  18. '!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!login_url' => $onetime,
  19. '!uri' => $base_url, '!uri_brief' => preg_replace('!^https?://!', '', $base_url), '!mailto' => $account->mail,
  20. '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)),
  21. '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)));
  22. $mail_success = drupal_mail('install', 'welcome-admin', $account->mail, user_preferred_language($account), $mail_params, $from, TRUE);
  23. if ($mail_success) {
  24. drush_log(dt('Sent welcome mail to @client', array('@client' => $client_email)), 'success');
  25. }
  26. else {
  27. drush_log(dt('Could not send welcome mail to @client', array('@client' => $client_email)), 'warning');
  28. }
  29. }
  30. }
  31. function install_mail($key, &$message, $params) {
  32. global $profile;
  33. switch ($key) {
  34. case 'welcome-admin':
  35. // allow the profile to override welcome email text
  36. if (file_exists("./profiles/$profile/provision_welcome_mail.inc")) {
  37. require_once "./profiles/$profile/provision_welcome_mail.inc";
  38. $custom = TRUE;
  39. }
  40. elseif (file_exists(dirname(__FILE__) . '/../provision_welcome_mail.inc')) {
  41. /** use the module provided welcome email
  42. * We can not use drupal_get_path here,
  43. * as we are connected to the provisioned site's database
  44. */
  45. require_once dirname(__FILE__) . '/../provision_welcome_mail.inc';
  46. $custom = TRUE;
  47. }
  48. else {
  49. // last resort use the user-pass mail text
  50. $custom = FALSE;
  51. }
  52. if ($custom) {
  53. $message['subject'] = dt($mail['subject'], $params['variables']);
  54. $message['body'][] = dt($mail['body'], $params['variables']);
  55. }
  56. else {
  57. $message['subject'] = _user_mail_text('pass_subject', $params['variables']);
  58. $message['body'][] = _user_mail_text('pass_body', $params['variables']);
  59. }
  60. break;
  61. }
  62. }
  63. function install_main() {
  64. global $profile, $install_locale, $conf, $url, $base_url;
  65. require_once DRUPAL_ROOT . '/includes/install.core.inc';
  66. require_once DRUPAL_ROOT . '/includes/entity.inc';
  67. require_once DRUPAL_ROOT . '/includes/unicode.inc';
  68. require_once DRUPAL_ROOT . '/modules/user/user.module';
  69. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
  70. // We have an existing settings.php.
  71. switch (substr(drush_core_version(), 0, 1)) {
  72. case '8':
  73. case '7':
  74. $sql = drush_get_class('Drush\Sql\Sql', array(), array(drush_drupal_major_version()));
  75. $db_spec = $sql->get_db_spec();
  76. break;
  77. case '6':
  78. case '5':
  79. $db_spec = _drush_sql_get_db_spec();
  80. break;
  81. default:
  82. drush_set_error('DRUSH_UNSUPPORTED_VERSION', dt('Drush !version is not supported'));
  83. }
  84. $db_spec['db_prefix'] = $GLOBALS['db_prefix'];
  85. if ($db_spec['driver'] == 'mysqli') {
  86. $db_spec['driver'] = 'mysql';
  87. }
  88. unset($conf['site_name']);
  89. unset($conf['site_mail']);
  90. unset($GLOBALS['db_url']);
  91. $account_pass = provision_password();
  92. $name = drush_get_option('admin_user', PROVISION_DEFAULT_ADMIN_USER);
  93. if ($error = user_validate_name($name)) {
  94. drush_log(dt('Error setting UID username to `!user`: ', array('!user' => $name)) . $error . dt(' Using default (!default) instead.', array('!default' => PROVISION_DEFAULT_ADMIN_USER)) , 'warning');
  95. $name = PROVISION_DEFAULT_ADMIN_USER;
  96. }
  97. $client_email = install_validate_client_email(drush_get_option('client_email', FALSE));
  98. $settings = array(
  99. 'parameters' => array(
  100. 'profile' => $profile,
  101. 'locale' => $install_locale,
  102. ),
  103. 'settings_verified' => TRUE,
  104. 'forms' => array(
  105. 'install_settings_form' => $db_spec,
  106. 'install_configure_form' => array(
  107. 'site_name' => $url,
  108. 'site_mail' => $client_email,
  109. 'account' => array(
  110. 'name' => $name,
  111. 'mail' => $client_email,
  112. 'pass' => array(
  113. 'pass1' => $account_pass,
  114. 'pass2' => $account_pass,
  115. ),
  116. ),
  117. 'update_status_module' => array(
  118. 1 => TRUE,
  119. 2 => TRUE,
  120. ),
  121. 'clean_url' => drush_get_option('clean_url', TRUE),
  122. ),
  123. ),
  124. );
  125. // Allow other commands to alter the installation settings.
  126. drush_command_invoke_all_ref('provision_drupal_install_settings_alter', $settings, $url);
  127. try {
  128. install_drupal($settings);
  129. }
  130. catch (Exception $e) {
  131. drush_set_error('DRUPAL_INSTALL_FAILED');
  132. drush_log('Site installation caused an exception.', 'error');
  133. dlm($e);
  134. }
  135. _provision_drupal_create_directories();
  136. $account = user_load(1);
  137. $onetime = user_pass_reset_url($account);
  138. // Store the one time login link in an option so the front end can direct the user to their new site.
  139. drush_set_option('login_link', $onetime . '/login');
  140. drush_log(dt('Login url: !onetime', array('!onetime' => $onetime . '/login')), 'success');
  141. if (drush_get_option('client_email', FALSE)) {
  142. install_send_welcome_mail($url, $account, $install_locale, $client_email, $onetime);
  143. }
  144. }
  145. install_main();
  146. function install_exception_handler() {
  147. dlm(func_get_args());
  148. }