site_install_6.inc

  1. 8.0.x commands/core/drupal/site_install_6.inc
  2. 6.x commands/core/drupal/site_install_6.inc
  3. 7.x commands/core/drupal/site_install_6.inc
  4. 4.x commands/core/drupal/site_install_6.inc
  5. 5.x commands/core/drupal/site_install_6.inc

Functions

Namesort descending Description
drush_core_site_install_version Install Drupal 6.x
_drush_site_install6_cookies Utility function to grab/set current "cli cookie".
_drush_site_install6_install_task Utility function to check the install_task. We are not bootstrapped to a high enough level to use variable_get.
_drush_site_install6_stage Submit a given op to install.php; if a meta "Refresh" tag is returned in the result, then submit that op as well.

File

commands/core/drupal/site_install_6.inc
View source
  1. <?php
  2. use Drush\Log\LogLevel;
  3. /**
  4. * Install Drupal 6.x
  5. */
  6. function drush_core_site_install_version($profile, array $additional_form_options = array()) {
  7. drush_log(dt('Starting Drupal installation. This takes a few seconds ...'), LogLevel::OK);
  8. if (!isset($profile)) {
  9. $profile = 'default';
  10. }
  11. $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
  12. // We need to disable reporting of E_NOTICE if we want to read the command's output
  13. // on Windows, because of how Windows is handling output order when using 2>&1
  14. // redirect added to the command in drush_shell_exec(). We will actually take out
  15. // all but fatal errors. See http://drupal.org/node/985716 for more information.
  16. $phpcode = 'error_reporting(E_ERROR);' . _drush_site_install6_cookies($profile). ' include("'. $drupal_root .'/install.php");';
  17. drush_shell_exec('php -r %s', $phpcode);
  18. $cli_output = drush_shell_exec_output();
  19. $cli_cookie = end($cli_output);
  20. // We need to bootstrap the database to be able to check the progress of the
  21. // install batch process since we're not duplicating the install process using
  22. // drush_batch functions, but calling the process directly.
  23. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_DATABASE);
  24. $status = _drush_site_install6_stage($profile, $cli_cookie, "start");
  25. if ($status === FALSE) {
  26. return FALSE;
  27. }
  28. $status = _drush_site_install6_stage($profile, $cli_cookie, "do_nojs");
  29. if ($status === FALSE) {
  30. return FALSE;
  31. }
  32. $status = _drush_site_install6_stage($profile, $cli_cookie, "finished");
  33. if ($status === FALSE) {
  34. return FALSE;
  35. }
  36. $account_pass = drush_get_option('account-pass', drush_generate_password());
  37. $account_name = drush_get_option('account-name', 'admin');
  38. $phpcode = _drush_site_install6_cookies($profile, $cli_cookie);
  39. $post = array (
  40. "site_name" => drush_get_option('site-name', 'Site-Install'),
  41. "site_mail" => drush_get_option('site-mail', 'admin@example.com'),
  42. "account" => array (
  43. "name" => $account_name,
  44. "mail" => drush_get_option('account-mail', 'admin@example.com'),
  45. "pass" => array (
  46. "pass1" => $account_pass,
  47. "pass2" => $account_pass,
  48. )
  49. ),
  50. "date_default_timezone" => "0",
  51. "clean_url" => drush_get_option('clean-url', TRUE),
  52. "form_id" => "install_configure_form",
  53. "update_status_module" => array("1" => "1"),
  54. );
  55. // Merge in the additional options.
  56. foreach ($additional_form_options as $key => $value) {
  57. $current = &$post;
  58. foreach (explode('.', $key) as $param) {
  59. $current = &$current[$param];
  60. }
  61. $current = $value;
  62. }
  63. $phpcode .= '
  64. $_POST = ' . var_export($post, true) . ';
  65. include("'. $drupal_root .'/install.php");';
  66. drush_shell_exec('php -r %s', $phpcode);
  67. drush_log(dt('Installation complete. User name: @name User password: @pass', array('@name' => $account_name, '@pass' => $account_pass)), LogLevel::OK);
  68. }
  69. /**
  70. * Submit a given op to install.php; if a meta "Refresh" tag
  71. * is returned in the result, then submit that op as well.
  72. */
  73. function _drush_site_install6_stage($profile, $cli_cookie, $initial_op) {
  74. $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
  75. // Remember the install task at the start of the stage
  76. $install_task = _drush_site_install6_install_task();
  77. $op = $initial_op;
  78. while (!empty($op)) {
  79. $phpcode = _drush_site_install6_cookies($profile, $cli_cookie). ' $_GET["op"]="' . $op . '"; include("'. $drupal_root .'/install.php");';
  80. drush_shell_exec('php -r %s', $phpcode);
  81. $output = implode("\n", drush_shell_exec_output());
  82. // Check for a "Refresh" back to the do_nojs op; e.g.:
  83. // <meta http-equiv="Refresh" content="0; URL=http://default/install.php?locale=en&profile=wk_profile6&id=1&op=do_nojs">
  84. // If this pattern is NOT found, then go on to the "finished" step.
  85. $matches = array();
  86. $match_result = preg_match('/http-equiv="Refresh".*op=([a-zA-Z0-9_]*)/', $output, $matches);
  87. if ($match_result) {
  88. $op = $matches[1];
  89. }
  90. else {
  91. $op = '';
  92. }
  93. }
  94. if (($install_task == _drush_site_install6_install_task()) && ($initial_op != "finished")) {
  95. return drush_set_error('DRUSH_SITE_INSTALL_FAILED', dt("The site install task '!task' failed.", array('!task' => $install_task)));
  96. }
  97. return TRUE;
  98. }
  99. /**
  100. * Utility function to grab/set current "cli cookie".
  101. */
  102. function _drush_site_install6_cookies($profile, $cookie = NULL) {
  103. $drupal_base_url = parse_url(drush_get_context('DRUSH_SELECTED_URI'));
  104. $output = '$_GET=array("profile"=>"' . $profile . '", "locale"=>"' . drush_get_option('locale', 'en') . '", "id"=>"1"); $_REQUEST=&$_GET;';
  105. $output .= 'define("DRUSH_SITE_INSTALL6", TRUE);$_SERVER["SERVER_SOFTWARE"] = NULL;';
  106. $output .= '$_SERVER["SCRIPT_NAME"] = "/install.php";';
  107. $output .= '$_SERVER["HTTP_HOST"] = "'.$drupal_base_url['host'].'";';
  108. $output .= '$_SERVER["REMOTE_ADDR"] = "127.0.0.1";';
  109. if ($cookie) {
  110. $output .= sprintf('$_COOKIE=unserialize("%s");', str_replace('"', '\"', $cookie));
  111. }
  112. else {
  113. $output .= 'function _cli_cookie_print(){print(serialize(array(session_name()=>session_id())));} register_shutdown_function("_cli_cookie_print");';
  114. }
  115. return $output;
  116. }
  117. /**
  118. * Utility function to check the install_task. We are
  119. * not bootstrapped to a high enough level to use variable_get.
  120. */
  121. function _drush_site_install6_install_task() {
  122. if ($data = db_result(db_query("SELECT value FROM {variable} WHERE name = 'install_task'",1))) {
  123. $result = unserialize($data);
  124. }
  125. return $result;
  126. }