Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / drupal / site_install_6.inc
1 <?php
2
3 use Drush\Log\LogLevel;
4
5 /**
6  * Install Drupal 6.x
7  */
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)) {
11     $profile = 'default';
12   }
13   $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
14
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);
23
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);
28
29   $status = _drush_site_install6_stage($profile, $cli_cookie, "start");
30   if ($status === FALSE) {
31     return FALSE;
32   }
33
34   $status = _drush_site_install6_stage($profile, $cli_cookie, "do_nojs");
35   if ($status === FALSE) {
36     return FALSE;
37   }
38
39   $status = _drush_site_install6_stage($profile, $cli_cookie, "finished");
40   if ($status === FALSE) {
41     return FALSE;
42   }
43
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);
47   if (!$account_pass) {
48     $account_pass = drush_generate_password();
49   }
50   $phpcode = _drush_site_install6_cookies($profile, $cli_cookie);
51   $post = array (
52     "site_name" => drush_get_option('site-name', 'Site-Install'),
53     "site_mail" => drush_get_option('site-mail', 'admin@example.com'),
54     "account" => array (
55       "name" => $account_name,
56       "mail" => drush_get_option('account-mail', 'admin@example.com'),
57       "pass" => array (
58         "pass1" => $account_pass,
59         "pass2" => $account_pass,
60       )
61     ),
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"),
66   );
67   // Merge in the additional options.
68   foreach ($additional_form_options as $key => $value) {
69     $current = &$post;
70     foreach (explode('.', $key) as $param) {
71       $current = &$current[$param];
72     }
73     $current = $value;
74   }
75   $phpcode .= '
76   $_POST = ' . var_export($post, true) . ';
77   include("'. $drupal_root .'/install.php");';
78   drush_shell_exec('php -r %s', $phpcode);
79
80   if ($show_password) {
81     drush_log(dt('Installation complete.  User name: @name  User password: @pass', array('@name' => $account_name, '@pass' => $account_pass)), LogLevel::OK);
82   }
83   else {
84     drush_log(dt('Installation complete.'), LogLevel::OK);
85   }
86 }
87
88 /**
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.
91  */
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();
96   $op = $initial_op;
97   while (!empty($op)) {
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.
104     $matches = array();
105     $match_result = preg_match('/http-equiv="Refresh".*op=([a-zA-Z0-9_]*)/', $output, $matches);
106     if ($match_result) {
107       $op = $matches[1];
108     }
109     else {
110       $op = '';
111     }
112   }
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)));
115   }
116   return TRUE;
117 }
118
119 /**
120  * Utility function to grab/set current "cli cookie".
121  */
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";';
129
130   if ($cookie) {
131     $output .= sprintf('$_COOKIE=unserialize("%s");', str_replace('"', '\"', $cookie));
132   }
133   else {
134     $output .= 'function _cli_cookie_print(){print(serialize(array(session_name()=>session_id())));} register_shutdown_function("_cli_cookie_print");';
135   }
136
137   return $output;
138 }
139
140 /**
141  * Utility function to check the install_task.  We are
142  * not bootstrapped to a high enough level to use variable_get.
143  */
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);
147   }
148   return $result;
149 }