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