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