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