webmaster@1
|
1 <?php |
webmaster@7
|
2 // $Id: install.php,v 1.113.2.3 2008/07/09 19:15:59 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 require_once './includes/install.inc'; |
webmaster@1
|
5 |
webmaster@1
|
6 define('MAINTENANCE_MODE', 'install'); |
webmaster@1
|
7 |
webmaster@1
|
8 /** |
webmaster@1
|
9 * The Drupal installation happens in a series of steps. We begin by verifying |
webmaster@1
|
10 * that the current environment meets our minimum requirements. We then go |
webmaster@1
|
11 * on to verify that settings.php is properly configured. From there we |
webmaster@1
|
12 * connect to the configured database and verify that it meets our minimum |
webmaster@1
|
13 * requirements. Finally we can allow the user to select an installation |
webmaster@1
|
14 * profile and complete the installation process. |
webmaster@1
|
15 * |
webmaster@1
|
16 * @param $phase |
webmaster@1
|
17 * The installation phase we should proceed to. |
webmaster@1
|
18 */ |
webmaster@1
|
19 function install_main() { |
webmaster@1
|
20 require_once './includes/bootstrap.inc'; |
webmaster@1
|
21 drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); |
webmaster@1
|
22 |
webmaster@1
|
23 // This must go after drupal_bootstrap(), which unsets globals! |
webmaster@1
|
24 global $profile, $install_locale, $conf; |
webmaster@1
|
25 |
webmaster@1
|
26 require_once './modules/system/system.install'; |
webmaster@1
|
27 require_once './includes/file.inc'; |
webmaster@1
|
28 |
webmaster@1
|
29 // Ensure correct page headers are sent (e.g. caching) |
webmaster@1
|
30 drupal_page_header(); |
webmaster@1
|
31 |
webmaster@1
|
32 // Set up $language, so t() caller functions will still work. |
webmaster@1
|
33 drupal_init_language(); |
webmaster@1
|
34 |
webmaster@1
|
35 // Load module basics (needed for hook invokes). |
webmaster@1
|
36 include_once './includes/module.inc'; |
webmaster@1
|
37 $module_list['system']['filename'] = 'modules/system/system.module'; |
webmaster@1
|
38 $module_list['filter']['filename'] = 'modules/filter/filter.module'; |
webmaster@1
|
39 module_list(TRUE, FALSE, FALSE, $module_list); |
webmaster@1
|
40 drupal_load('module', 'system'); |
webmaster@1
|
41 drupal_load('module', 'filter'); |
webmaster@1
|
42 |
webmaster@1
|
43 // Set up theme system for the maintenance page. |
webmaster@1
|
44 drupal_maintenance_theme(); |
webmaster@1
|
45 |
webmaster@1
|
46 // Check existing settings.php. |
webmaster@1
|
47 $verify = install_verify_settings(); |
webmaster@1
|
48 |
webmaster@1
|
49 if ($verify) { |
webmaster@1
|
50 // Since we have a database connection, we use the normal cache system. |
webmaster@1
|
51 // This is important, as the installer calls into the Drupal system for |
webmaster@1
|
52 // the clean URL checks, so we should maintain the cache properly. |
webmaster@1
|
53 require_once './includes/cache.inc'; |
webmaster@1
|
54 $conf['cache_inc'] = './includes/cache.inc'; |
webmaster@1
|
55 |
webmaster@1
|
56 // Establish a connection to the database. |
webmaster@1
|
57 require_once './includes/database.inc'; |
webmaster@1
|
58 db_set_active(); |
webmaster@1
|
59 |
webmaster@1
|
60 // Check if Drupal is installed. |
webmaster@1
|
61 $task = install_verify_drupal(); |
webmaster@1
|
62 if ($task == 'done') { |
webmaster@1
|
63 install_already_done_error(); |
webmaster@1
|
64 } |
webmaster@1
|
65 } |
webmaster@1
|
66 else { |
webmaster@1
|
67 // Since no persistent storage is available yet, and functions that check |
webmaster@1
|
68 // for cached data will fail, we temporarily replace the normal cache |
webmaster@1
|
69 // system with a stubbed-out version that short-circuits the actual |
webmaster@1
|
70 // caching process and avoids any errors. |
webmaster@1
|
71 require_once './includes/cache-install.inc'; |
webmaster@1
|
72 $conf['cache_inc'] = './includes/cache-install.inc'; |
webmaster@1
|
73 |
webmaster@1
|
74 $task = NULL; |
webmaster@1
|
75 } |
webmaster@1
|
76 |
webmaster@1
|
77 // Decide which profile to use. |
webmaster@1
|
78 if (!empty($_GET['profile'])) { |
webmaster@1
|
79 $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']); |
webmaster@1
|
80 } |
webmaster@1
|
81 elseif ($profile = install_select_profile()) { |
webmaster@1
|
82 install_goto("install.php?profile=$profile"); |
webmaster@1
|
83 } |
webmaster@1
|
84 else { |
webmaster@1
|
85 install_no_profile_error(); |
webmaster@1
|
86 } |
webmaster@1
|
87 |
webmaster@1
|
88 // Load the profile. |
webmaster@1
|
89 require_once "./profiles/$profile/$profile.profile"; |
webmaster@1
|
90 |
webmaster@1
|
91 // Locale selection |
webmaster@1
|
92 if (!empty($_GET['locale'])) { |
webmaster@1
|
93 $install_locale = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['locale']); |
webmaster@1
|
94 } |
webmaster@1
|
95 elseif (($install_locale = install_select_locale($profile)) !== FALSE) { |
webmaster@1
|
96 install_goto("install.php?profile=$profile&locale=$install_locale"); |
webmaster@1
|
97 } |
webmaster@1
|
98 |
webmaster@1
|
99 // Tasks come after the database is set up |
webmaster@1
|
100 if (!$task) { |
webmaster@7
|
101 global $db_url; |
webmaster@7
|
102 |
webmaster@7
|
103 if (!$verify && !empty($db_url)) { |
webmaster@7
|
104 // Do not install over a configured settings.php. |
webmaster@7
|
105 install_already_done_error(); |
webmaster@7
|
106 } |
webmaster@7
|
107 |
webmaster@1
|
108 // Check the installation requirements for Drupal and this profile. |
webmaster@1
|
109 install_check_requirements($profile, $verify); |
webmaster@1
|
110 |
webmaster@1
|
111 // Verify existence of all required modules. |
webmaster@1
|
112 $modules = drupal_verify_profile($profile, $install_locale); |
webmaster@1
|
113 |
webmaster@1
|
114 // If any error messages are set now, it means a requirement problem. |
webmaster@1
|
115 $messages = drupal_set_message(); |
webmaster@1
|
116 if (!empty($messages['error'])) { |
webmaster@1
|
117 install_task_list('requirements'); |
webmaster@1
|
118 drupal_set_title(st('Requirements problem')); |
webmaster@1
|
119 print theme('install_page', ''); |
webmaster@1
|
120 exit; |
webmaster@1
|
121 } |
webmaster@1
|
122 |
webmaster@1
|
123 // Change the settings.php information if verification failed earlier. |
webmaster@1
|
124 // Note: will trigger a redirect if database credentials change. |
webmaster@1
|
125 if (!$verify) { |
webmaster@1
|
126 install_change_settings($profile, $install_locale); |
webmaster@1
|
127 } |
webmaster@1
|
128 |
webmaster@1
|
129 // Install system.module. |
webmaster@1
|
130 drupal_install_system(); |
webmaster@1
|
131 // Save the list of other modules to install for the 'profile-install' |
webmaster@1
|
132 // task. variable_set() can be used now that system.module is installed |
webmaster@1
|
133 // and drupal is bootstrapped. |
webmaster@1
|
134 variable_set('install_profile_modules', array_diff($modules, array('system'))); |
webmaster@1
|
135 } |
webmaster@1
|
136 |
webmaster@1
|
137 // The database is set up, turn to further tasks. |
webmaster@1
|
138 install_tasks($profile, $task); |
webmaster@1
|
139 } |
webmaster@1
|
140 |
webmaster@1
|
141 /** |
webmaster@1
|
142 * Verify if Drupal is installed. |
webmaster@1
|
143 */ |
webmaster@1
|
144 function install_verify_drupal() { |
webmaster@1
|
145 // Read the variable manually using the @ so we don't trigger an error if it fails. |
webmaster@1
|
146 $result = @db_query("SELECT value FROM {variable} WHERE name = '%s'", 'install_task'); |
webmaster@1
|
147 if ($result) { |
webmaster@1
|
148 return unserialize(db_result($result)); |
webmaster@1
|
149 } |
webmaster@1
|
150 } |
webmaster@1
|
151 |
webmaster@1
|
152 /** |
webmaster@1
|
153 * Verify existing settings.php |
webmaster@1
|
154 */ |
webmaster@1
|
155 function install_verify_settings() { |
webmaster@1
|
156 global $db_prefix, $db_type, $db_url; |
webmaster@1
|
157 |
webmaster@1
|
158 // Verify existing settings (if any). |
webmaster@1
|
159 if (!empty($db_url)) { |
webmaster@1
|
160 // We need this because we want to run form_get_errors. |
webmaster@1
|
161 include_once './includes/form.inc'; |
webmaster@1
|
162 |
webmaster@1
|
163 $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url); |
webmaster@1
|
164 $db_user = urldecode($url['user']); |
webmaster@1
|
165 $db_pass = isset($url['pass']) ? urldecode($url['pass']) : NULL; |
webmaster@1
|
166 $db_host = urldecode($url['host']); |
webmaster@1
|
167 $db_port = isset($url['port']) ? urldecode($url['port']) : ''; |
webmaster@1
|
168 $db_path = ltrim(urldecode($url['path']), '/'); |
webmaster@1
|
169 $settings_file = './'. conf_path(FALSE, TRUE) .'/settings.php'; |
webmaster@1
|
170 |
webmaster@1
|
171 $form_state = array(); |
webmaster@1
|
172 _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, $form_state); |
webmaster@1
|
173 if (!form_get_errors()) { |
webmaster@1
|
174 return TRUE; |
webmaster@1
|
175 } |
webmaster@1
|
176 } |
webmaster@1
|
177 return FALSE; |
webmaster@1
|
178 } |
webmaster@1
|
179 |
webmaster@1
|
180 /** |
webmaster@1
|
181 * Configure and rewrite settings.php. |
webmaster@1
|
182 */ |
webmaster@1
|
183 function install_change_settings($profile = 'default', $install_locale = '') { |
webmaster@1
|
184 global $db_url, $db_type, $db_prefix; |
webmaster@1
|
185 |
webmaster@1
|
186 $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url); |
webmaster@1
|
187 $db_user = isset($url['user']) ? urldecode($url['user']) : ''; |
webmaster@1
|
188 $db_pass = isset($url['pass']) ? urldecode($url['pass']) : ''; |
webmaster@1
|
189 $db_host = isset($url['host']) ? urldecode($url['host']) : ''; |
webmaster@1
|
190 $db_port = isset($url['port']) ? urldecode($url['port']) : ''; |
webmaster@1
|
191 $db_path = ltrim(urldecode($url['path']), '/'); |
webmaster@1
|
192 $conf_path = './'. conf_path(FALSE, TRUE); |
webmaster@1
|
193 $settings_file = $conf_path .'/settings.php'; |
webmaster@1
|
194 |
webmaster@1
|
195 // We always need this because we want to run form_get_errors. |
webmaster@1
|
196 include_once './includes/form.inc'; |
webmaster@1
|
197 install_task_list('database'); |
webmaster@1
|
198 |
webmaster@1
|
199 $output = drupal_get_form('install_settings_form', $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path); |
webmaster@1
|
200 drupal_set_title(st('Database configuration')); |
webmaster@1
|
201 print theme('install_page', $output); |
webmaster@1
|
202 exit; |
webmaster@1
|
203 } |
webmaster@1
|
204 |
webmaster@1
|
205 |
webmaster@1
|
206 /** |
webmaster@1
|
207 * Form API array definition for install_settings. |
webmaster@1
|
208 */ |
webmaster@1
|
209 function install_settings_form(&$form_state, $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path) { |
webmaster@1
|
210 if (empty($db_host)) { |
webmaster@1
|
211 $db_host = 'localhost'; |
webmaster@1
|
212 } |
webmaster@1
|
213 $db_types = drupal_detect_database_types(); |
webmaster@1
|
214 |
webmaster@1
|
215 // If both 'mysql' and 'mysqli' are available, we disable 'mysql': |
webmaster@1
|
216 if (isset($db_types['mysqli'])) { |
webmaster@1
|
217 unset($db_types['mysql']); |
webmaster@1
|
218 } |
webmaster@1
|
219 |
webmaster@1
|
220 if (count($db_types) == 0) { |
webmaster@1
|
221 $form['no_db_types'] = array( |
webmaster@1
|
222 '#value' => st('Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that <a href="@drupal-databases">Drupal supports</a>.', array('@drupal-databases' => 'http://drupal.org/node/270#database')), |
webmaster@1
|
223 ); |
webmaster@1
|
224 } |
webmaster@1
|
225 else { |
webmaster@1
|
226 $form['basic_options'] = array( |
webmaster@1
|
227 '#type' => 'fieldset', |
webmaster@1
|
228 '#title' => st('Basic options'), |
webmaster@1
|
229 '#description' => '<p>'. st('To set up your @drupal database, enter the following information.', array('@drupal' => drupal_install_profile_name())) .'</p>', |
webmaster@1
|
230 ); |
webmaster@1
|
231 |
webmaster@1
|
232 if (count($db_types) > 1) { |
webmaster@1
|
233 $form['basic_options']['db_type'] = array( |
webmaster@1
|
234 '#type' => 'radios', |
webmaster@1
|
235 '#title' => st('Database type'), |
webmaster@1
|
236 '#required' => TRUE, |
webmaster@1
|
237 '#options' => $db_types, |
webmaster@1
|
238 '#default_value' => ($db_type ? $db_type : current($db_types)), |
webmaster@1
|
239 '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_name())), |
webmaster@1
|
240 ); |
webmaster@1
|
241 $db_path_description = st('The name of the database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('@drupal' => drupal_install_profile_name())); |
webmaster@1
|
242 } |
webmaster@1
|
243 else { |
webmaster@1
|
244 if (count($db_types) == 1) { |
webmaster@1
|
245 $db_types = array_values($db_types); |
webmaster@1
|
246 $form['basic_options']['db_type'] = array( |
webmaster@1
|
247 '#type' => 'hidden', |
webmaster@1
|
248 '#value' => $db_types[0], |
webmaster@1
|
249 ); |
webmaster@1
|
250 $db_path_description = st('The name of the %db_type database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('%db_type' => $db_types[0], '@drupal' => drupal_install_profile_name())); |
webmaster@1
|
251 } |
webmaster@1
|
252 } |
webmaster@1
|
253 |
webmaster@1
|
254 // Database name |
webmaster@1
|
255 $form['basic_options']['db_path'] = array( |
webmaster@1
|
256 '#type' => 'textfield', |
webmaster@1
|
257 '#title' => st('Database name'), |
webmaster@1
|
258 '#default_value' => $db_path, |
webmaster@1
|
259 '#size' => 45, |
webmaster@1
|
260 '#maxlength' => 45, |
webmaster@1
|
261 '#required' => TRUE, |
webmaster@1
|
262 '#description' => $db_path_description |
webmaster@1
|
263 ); |
webmaster@1
|
264 |
webmaster@1
|
265 // Database username |
webmaster@1
|
266 $form['basic_options']['db_user'] = array( |
webmaster@1
|
267 '#type' => 'textfield', |
webmaster@1
|
268 '#title' => st('Database username'), |
webmaster@1
|
269 '#default_value' => $db_user, |
webmaster@1
|
270 '#size' => 45, |
webmaster@1
|
271 '#maxlength' => 45, |
webmaster@1
|
272 '#required' => TRUE, |
webmaster@1
|
273 ); |
webmaster@1
|
274 |
webmaster@1
|
275 // Database username |
webmaster@1
|
276 $form['basic_options']['db_pass'] = array( |
webmaster@1
|
277 '#type' => 'password', |
webmaster@1
|
278 '#title' => st('Database password'), |
webmaster@1
|
279 '#default_value' => $db_pass, |
webmaster@1
|
280 '#size' => 45, |
webmaster@1
|
281 '#maxlength' => 45, |
webmaster@1
|
282 ); |
webmaster@1
|
283 |
webmaster@1
|
284 $form['advanced_options'] = array( |
webmaster@1
|
285 '#type' => 'fieldset', |
webmaster@1
|
286 '#title' => st('Advanced options'), |
webmaster@1
|
287 '#collapsible' => TRUE, |
webmaster@1
|
288 '#collapsed' => TRUE, |
webmaster@1
|
289 '#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider.") |
webmaster@1
|
290 ); |
webmaster@1
|
291 |
webmaster@1
|
292 // Database host |
webmaster@1
|
293 $form['advanced_options']['db_host'] = array( |
webmaster@1
|
294 '#type' => 'textfield', |
webmaster@1
|
295 '#title' => st('Database host'), |
webmaster@1
|
296 '#default_value' => $db_host, |
webmaster@1
|
297 '#size' => 45, |
webmaster@1
|
298 '#maxlength' => 45, |
webmaster@1
|
299 '#required' => TRUE, |
webmaster@1
|
300 '#description' => st('If your database is located on a different server, change this.'), |
webmaster@1
|
301 ); |
webmaster@1
|
302 |
webmaster@1
|
303 // Database port |
webmaster@1
|
304 $form['advanced_options']['db_port'] = array( |
webmaster@1
|
305 '#type' => 'textfield', |
webmaster@1
|
306 '#title' => st('Database port'), |
webmaster@1
|
307 '#default_value' => $db_port, |
webmaster@1
|
308 '#size' => 45, |
webmaster@1
|
309 '#maxlength' => 45, |
webmaster@1
|
310 '#description' => st('If your database server is listening to a non-standard port, enter its number.'), |
webmaster@1
|
311 ); |
webmaster@1
|
312 |
webmaster@1
|
313 // Table prefix |
webmaster@1
|
314 $prefix = ($profile == 'default') ? 'drupal_' : $profile .'_'; |
webmaster@1
|
315 $form['advanced_options']['db_prefix'] = array( |
webmaster@1
|
316 '#type' => 'textfield', |
webmaster@1
|
317 '#title' => st('Table prefix'), |
webmaster@1
|
318 '#default_value' => $db_prefix, |
webmaster@1
|
319 '#size' => 45, |
webmaster@1
|
320 '#maxlength' => 45, |
webmaster@1
|
321 '#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_name(), '%prefix' => $prefix)), |
webmaster@1
|
322 ); |
webmaster@1
|
323 |
webmaster@1
|
324 $form['save'] = array( |
webmaster@1
|
325 '#type' => 'submit', |
webmaster@1
|
326 '#value' => st('Save and continue'), |
webmaster@1
|
327 ); |
webmaster@1
|
328 |
webmaster@1
|
329 $form['errors'] = array(); |
webmaster@1
|
330 $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file); |
webmaster@1
|
331 $form['_db_url'] = array('#type' => 'value'); |
webmaster@1
|
332 $form['#action'] = "install.php?profile=$profile". ($install_locale ? "&locale=$install_locale" : ''); |
webmaster@1
|
333 $form['#redirect'] = FALSE; |
webmaster@1
|
334 } |
webmaster@1
|
335 return $form; |
webmaster@1
|
336 } |
webmaster@1
|
337 |
webmaster@1
|
338 /** |
webmaster@1
|
339 * Form API validate for install_settings form. |
webmaster@1
|
340 */ |
webmaster@1
|
341 function install_settings_form_validate($form, &$form_state) { |
webmaster@1
|
342 global $db_url; |
webmaster@1
|
343 _install_settings_form_validate($form_state['values']['db_prefix'], $form_state['values']['db_type'], $form_state['values']['db_user'], $form_state['values']['db_pass'], $form_state['values']['db_host'], $form_state['values']['db_port'], $form_state['values']['db_path'], $form_state['values']['settings_file'], $form_state, $form); |
webmaster@1
|
344 } |
webmaster@1
|
345 |
webmaster@1
|
346 /** |
webmaster@1
|
347 * Helper function for install_settings_validate. |
webmaster@1
|
348 */ |
webmaster@1
|
349 function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, &$form_state, $form = NULL) { |
webmaster@1
|
350 global $db_url; |
webmaster@1
|
351 |
webmaster@1
|
352 // Verify the table prefix |
webmaster@1
|
353 if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_.]+$/', $db_prefix)) { |
webmaster@1
|
354 form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $db_prefix)), 'error'); |
webmaster@1
|
355 } |
webmaster@1
|
356 |
webmaster@1
|
357 if (!empty($db_port) && !is_numeric($db_port)) { |
webmaster@1
|
358 form_set_error('db_port', st('Database port must be a number.')); |
webmaster@1
|
359 } |
webmaster@1
|
360 |
webmaster@1
|
361 // Check database type |
webmaster@1
|
362 if (!isset($form)) { |
webmaster@1
|
363 $_db_url = is_array($db_url) ? $db_url['default'] : $db_url; |
webmaster@1
|
364 $db_type = substr($_db_url, 0, strpos($_db_url, '://')); |
webmaster@1
|
365 } |
webmaster@1
|
366 $databases = drupal_detect_database_types(); |
webmaster@1
|
367 if (!in_array($db_type, $databases)) { |
webmaster@1
|
368 form_set_error('db_type', st("In your %settings_file file you have configured @drupal to use a %db_type server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%db_type' => $db_type))); |
webmaster@1
|
369 } |
webmaster@1
|
370 else { |
webmaster@1
|
371 // Verify |
webmaster@1
|
372 $db_url = $db_type .'://'. urlencode($db_user) . ($db_pass ? ':'. urlencode($db_pass) : '') .'@'. ($db_host ? urlencode($db_host) : 'localhost') . ($db_port ? ":$db_port" : '') .'/'. urlencode($db_path); |
webmaster@1
|
373 if (isset($form)) { |
webmaster@1
|
374 form_set_value($form['_db_url'], $db_url, $form_state); |
webmaster@1
|
375 } |
webmaster@1
|
376 $success = array(); |
webmaster@1
|
377 |
webmaster@1
|
378 $function = 'drupal_test_'. $db_type; |
webmaster@1
|
379 if (!$function($db_url, $success)) { |
webmaster@1
|
380 if (isset($success['CONNECT'])) { |
webmaster@1
|
381 form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($success, ', ')))); |
webmaster@1
|
382 } |
webmaster@1
|
383 else { |
webmaster@1
|
384 form_set_error('db_type', ''); |
webmaster@1
|
385 } |
webmaster@1
|
386 } |
webmaster@1
|
387 } |
webmaster@1
|
388 } |
webmaster@1
|
389 |
webmaster@1
|
390 /** |
webmaster@1
|
391 * Form API submit for install_settings form. |
webmaster@1
|
392 */ |
webmaster@1
|
393 function install_settings_form_submit($form, &$form_state) { |
webmaster@1
|
394 global $profile, $install_locale; |
webmaster@1
|
395 |
webmaster@1
|
396 // Update global settings array and save |
webmaster@1
|
397 $settings['db_url'] = array( |
webmaster@1
|
398 'value' => $form_state['values']['_db_url'], |
webmaster@1
|
399 'required' => TRUE, |
webmaster@1
|
400 ); |
webmaster@1
|
401 $settings['db_prefix'] = array( |
webmaster@1
|
402 'value' => $form_state['values']['db_prefix'], |
webmaster@1
|
403 'required' => TRUE, |
webmaster@1
|
404 ); |
webmaster@1
|
405 drupal_rewrite_settings($settings); |
webmaster@1
|
406 |
webmaster@1
|
407 // Continue to install profile step |
webmaster@1
|
408 install_goto("install.php?profile=$profile". ($install_locale ? "&locale=$install_locale" : '')); |
webmaster@1
|
409 } |
webmaster@1
|
410 |
webmaster@1
|
411 /** |
webmaster@1
|
412 * Find all .profile files. |
webmaster@1
|
413 */ |
webmaster@1
|
414 function install_find_profiles() { |
webmaster@1
|
415 return file_scan_directory('./profiles', '\.profile$', array('.', '..', 'CVS'), 0, TRUE, 'name', 0); |
webmaster@1
|
416 } |
webmaster@1
|
417 |
webmaster@1
|
418 /** |
webmaster@1
|
419 * Allow admin to select which profile to install. |
webmaster@1
|
420 * |
webmaster@1
|
421 * @return |
webmaster@1
|
422 * The selected profile. |
webmaster@1
|
423 */ |
webmaster@1
|
424 function install_select_profile() { |
webmaster@1
|
425 include_once './includes/form.inc'; |
webmaster@1
|
426 |
webmaster@1
|
427 $profiles = install_find_profiles(); |
webmaster@1
|
428 // Don't need to choose profile if only one available. |
webmaster@1
|
429 if (sizeof($profiles) == 1) { |
webmaster@1
|
430 $profile = array_pop($profiles); |
webmaster@1
|
431 require_once $profile->filename; |
webmaster@1
|
432 return $profile->name; |
webmaster@1
|
433 } |
webmaster@1
|
434 elseif (sizeof($profiles) > 1) { |
webmaster@1
|
435 foreach ($profiles as $profile) { |
webmaster@1
|
436 if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) { |
webmaster@1
|
437 return $profile->name; |
webmaster@1
|
438 } |
webmaster@1
|
439 } |
webmaster@1
|
440 |
webmaster@1
|
441 install_task_list('profile-select'); |
webmaster@1
|
442 |
webmaster@1
|
443 drupal_set_title(st('Select an installation profile')); |
webmaster@1
|
444 print theme('install_page', drupal_get_form('install_select_profile_form', $profiles)); |
webmaster@1
|
445 exit; |
webmaster@1
|
446 } |
webmaster@1
|
447 } |
webmaster@1
|
448 |
webmaster@1
|
449 /** |
webmaster@1
|
450 * Form API array definition for the profile selection form. |
webmaster@1
|
451 */ |
webmaster@1
|
452 function install_select_profile_form(&$form_state, $profiles) { |
webmaster@1
|
453 foreach ($profiles as $profile) { |
webmaster@1
|
454 include_once($profile->filename); |
webmaster@1
|
455 // Load profile details. |
webmaster@1
|
456 $function = $profile->name .'_profile_details'; |
webmaster@1
|
457 if (function_exists($function)) { |
webmaster@1
|
458 $details = $function(); |
webmaster@1
|
459 } |
webmaster@1
|
460 // If set, used defined name. Otherwise use file name. |
webmaster@1
|
461 $name = isset($details['name']) ? $details['name'] : $profile->name; |
webmaster@1
|
462 $form['profile'][$name] = array( |
webmaster@1
|
463 '#type' => 'radio', |
webmaster@1
|
464 '#value' => 'default', |
webmaster@1
|
465 '#return_value' => $profile->name, |
webmaster@1
|
466 '#title' => $name, |
webmaster@1
|
467 '#description' => isset($details['description']) ? $details['description'] : '', |
webmaster@1
|
468 '#parents' => array('profile'), |
webmaster@1
|
469 ); |
webmaster@1
|
470 } |
webmaster@1
|
471 $form['submit'] = array( |
webmaster@1
|
472 '#type' => 'submit', |
webmaster@1
|
473 '#value' => st('Save and continue'), |
webmaster@1
|
474 ); |
webmaster@1
|
475 return $form; |
webmaster@1
|
476 } |
webmaster@1
|
477 |
webmaster@1
|
478 /** |
webmaster@1
|
479 * Find all .po files for the current profile. |
webmaster@1
|
480 */ |
webmaster@1
|
481 function install_find_locales($profilename) { |
webmaster@1
|
482 $locales = file_scan_directory('./profiles/'. $profilename .'/translations', '\.po$', array('.', '..', 'CVS'), 0, FALSE); |
webmaster@1
|
483 array_unshift($locales, (object) array('name' => 'en')); |
webmaster@1
|
484 return $locales; |
webmaster@1
|
485 } |
webmaster@1
|
486 |
webmaster@1
|
487 /** |
webmaster@1
|
488 * Allow admin to select which locale to use for the current profile. |
webmaster@1
|
489 * |
webmaster@1
|
490 * @return |
webmaster@1
|
491 * The selected language. |
webmaster@1
|
492 */ |
webmaster@1
|
493 function install_select_locale($profilename) { |
webmaster@1
|
494 include_once './includes/file.inc'; |
webmaster@1
|
495 include_once './includes/form.inc'; |
webmaster@1
|
496 |
webmaster@1
|
497 // Find all available locales. |
webmaster@1
|
498 $locales = install_find_locales($profilename); |
webmaster@1
|
499 |
webmaster@1
|
500 // If only the built-in (English) language is available, |
webmaster@1
|
501 // and we are using the default profile, inform the user |
webmaster@1
|
502 // that the installer can be localized. Otherwise we assume |
webmaster@1
|
503 // the user know what he is doing. |
webmaster@1
|
504 if (count($locales) == 1) { |
webmaster@1
|
505 if ($profilename == 'default') { |
webmaster@1
|
506 install_task_list('locale-select'); |
webmaster@1
|
507 drupal_set_title(st('Choose language')); |
webmaster@1
|
508 if (!empty($_GET['localize'])) { |
webmaster@1
|
509 $output = '<p>'. st('With the addition of an appropriate translation package, this installer is capable of proceeding in another language of your choice. To install and use Drupal in a language other than English:') .'</p>'; |
webmaster@1
|
510 $output .= '<ul><li>'. st('Determine if <a href="@translations" target="_blank">a translation of this Drupal version</a> is available in your language of choice. A translation is provided via a translation package; each translation package enables the display of a specific version of Drupal in a specific language. Not all languages are available for every version of Drupal.', array('@translations' => 'http://drupal.org/project/translations')) .'</li>'; |
webmaster@1
|
511 $output .= '<li>'. st('If an alternative translation package of your choice is available, download and extract its contents to your Drupal root directory.') .'</li>'; |
webmaster@1
|
512 $output .= '<li>'. st('Return to choose language using the second link below and select your desired language from the displayed list. Reloading the page allows the list to automatically adjust to the presence of new translation packages.') .'</li>'; |
webmaster@1
|
513 $output .= '</ul><p>'. st('Alternatively, to install and use Drupal in English, or to defer the selection of an alternative language until after installation, select the first link below.') .'</p>'; |
webmaster@1
|
514 $output .= '<p>'. st('How should the installation continue?') .'</p>'; |
webmaster@1
|
515 $output .= '<ul><li><a href="install.php?profile='. $profilename .'&locale=en">'. st('Continue installation in English') .'</a></li><li><a href="install.php?profile='. $profilename .'">'. st('Return to choose a language') .'</a></li></ul>'; |
webmaster@1
|
516 } |
webmaster@1
|
517 else { |
webmaster@1
|
518 $output = '<ul><li><a href="install.php?profile='. $profilename .'&locale=en">'. st('Install Drupal in English') .'</a></li><li><a href="install.php?profile='. $profilename .'&localize=true">'. st('Learn how to install Drupal in other languages') .'</a></li></ul>'; |
webmaster@1
|
519 } |
webmaster@1
|
520 print theme('install_page', $output); |
webmaster@1
|
521 exit; |
webmaster@1
|
522 } |
webmaster@1
|
523 // One language, but not the default profile, assume |
webmaster@1
|
524 // the user knows what he is doing. |
webmaster@1
|
525 return FALSE; |
webmaster@1
|
526 } |
webmaster@1
|
527 else { |
webmaster@1
|
528 // Allow profile to pre-select the language, skipping the selection. |
webmaster@1
|
529 $function = $profilename .'_profile_details'; |
webmaster@1
|
530 if (function_exists($function)) { |
webmaster@1
|
531 $details = $function(); |
webmaster@1
|
532 if (isset($details['language'])) { |
webmaster@1
|
533 foreach ($locales as $locale) { |
webmaster@1
|
534 if ($details['language'] == $locale->name) { |
webmaster@1
|
535 return $locale->name; |
webmaster@1
|
536 } |
webmaster@1
|
537 } |
webmaster@1
|
538 } |
webmaster@1
|
539 } |
webmaster@1
|
540 |
webmaster@1
|
541 foreach ($locales as $locale) { |
webmaster@1
|
542 if ($_POST['locale'] == $locale->name) { |
webmaster@1
|
543 return $locale->name; |
webmaster@1
|
544 } |
webmaster@1
|
545 } |
webmaster@1
|
546 |
webmaster@1
|
547 install_task_list('locale-select'); |
webmaster@1
|
548 |
webmaster@1
|
549 drupal_set_title(st('Choose language')); |
webmaster@1
|
550 print theme('install_page', drupal_get_form('install_select_locale_form', $locales)); |
webmaster@1
|
551 exit; |
webmaster@1
|
552 } |
webmaster@1
|
553 } |
webmaster@1
|
554 |
webmaster@1
|
555 /** |
webmaster@1
|
556 * Form API array definition for language selection. |
webmaster@1
|
557 */ |
webmaster@1
|
558 function install_select_locale_form(&$form_state, $locales) { |
webmaster@1
|
559 include_once './includes/locale.inc'; |
webmaster@1
|
560 $languages = _locale_get_predefined_list(); |
webmaster@1
|
561 foreach ($locales as $locale) { |
webmaster@1
|
562 // Try to use verbose locale name |
webmaster@1
|
563 $name = $locale->name; |
webmaster@1
|
564 if (isset($languages[$name])) { |
webmaster@1
|
565 $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' '. st('(@language)', array('@language' => $languages[$name][1])) : ''); |
webmaster@1
|
566 } |
webmaster@1
|
567 $form['locale'][$locale->name] = array( |
webmaster@1
|
568 '#type' => 'radio', |
webmaster@1
|
569 '#return_value' => $locale->name, |
webmaster@1
|
570 '#default_value' => ($locale->name == 'en' ? TRUE : FALSE), |
webmaster@1
|
571 '#title' => $name . ($locale->name == 'en' ? ' '. st('(built-in)') : ''), |
webmaster@1
|
572 '#parents' => array('locale') |
webmaster@1
|
573 ); |
webmaster@1
|
574 } |
webmaster@1
|
575 $form['submit'] = array( |
webmaster@1
|
576 '#type' => 'submit', |
webmaster@1
|
577 '#value' => st('Select language'), |
webmaster@1
|
578 ); |
webmaster@1
|
579 return $form; |
webmaster@1
|
580 } |
webmaster@1
|
581 |
webmaster@1
|
582 /** |
webmaster@1
|
583 * Show an error page when there are no profiles available. |
webmaster@1
|
584 */ |
webmaster@1
|
585 function install_no_profile_error() { |
webmaster@1
|
586 install_task_list('profile-select'); |
webmaster@1
|
587 drupal_set_title(st('No profiles available')); |
webmaster@1
|
588 print theme('install_page', '<p>'. st('We were unable to find any installer profiles. Installer profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.') .'</p>'); |
webmaster@1
|
589 exit; |
webmaster@1
|
590 } |
webmaster@1
|
591 |
webmaster@1
|
592 |
webmaster@1
|
593 /** |
webmaster@1
|
594 * Show an error page when Drupal has already been installed. |
webmaster@1
|
595 */ |
webmaster@1
|
596 function install_already_done_error() { |
webmaster@1
|
597 global $base_url; |
webmaster@1
|
598 |
webmaster@1
|
599 drupal_set_title(st('Drupal already installed')); |
webmaster@1
|
600 print theme('install_page', st('<ul><li>To start over, you must empty your existing database.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To upgrade an existing installation, proceed to the <a href="@base-url/update.php">update script</a>.</li><li>View your <a href="@base-url">existing site</a>.</li></ul>', array('@base-url' => $base_url))); |
webmaster@1
|
601 exit; |
webmaster@1
|
602 } |
webmaster@1
|
603 |
webmaster@1
|
604 /** |
webmaster@1
|
605 * Tasks performed after the database is initialized. |
webmaster@1
|
606 */ |
webmaster@1
|
607 function install_tasks($profile, $task) { |
webmaster@1
|
608 global $base_url, $install_locale; |
webmaster@1
|
609 |
webmaster@1
|
610 // Bootstrap newly installed Drupal, while preserving existing messages. |
webmaster@1
|
611 $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : ''; |
webmaster@1
|
612 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
webmaster@1
|
613 $_SESSION['messages'] = $messages; |
webmaster@1
|
614 |
webmaster@1
|
615 // URL used to direct page requests. |
webmaster@1
|
616 $url = $base_url .'/install.php?locale='. $install_locale .'&profile='. $profile; |
webmaster@1
|
617 |
webmaster@1
|
618 // Build a page for final tasks. |
webmaster@1
|
619 if (empty($task)) { |
webmaster@1
|
620 variable_set('install_task', 'profile-install'); |
webmaster@1
|
621 $task = 'profile-install'; |
webmaster@1
|
622 } |
webmaster@1
|
623 |
webmaster@1
|
624 // We are using a list of if constructs here to allow for |
webmaster@1
|
625 // passing from one task to the other in the same request. |
webmaster@1
|
626 |
webmaster@1
|
627 // Install profile modules. |
webmaster@1
|
628 if ($task == 'profile-install') { |
webmaster@1
|
629 $modules = variable_get('install_profile_modules', array()); |
webmaster@1
|
630 $files = module_rebuild_cache(); |
webmaster@1
|
631 variable_del('install_profile_modules'); |
webmaster@1
|
632 $operations = array(); |
webmaster@1
|
633 foreach ($modules as $module) { |
webmaster@1
|
634 $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name'])); |
webmaster@1
|
635 } |
webmaster@1
|
636 $batch = array( |
webmaster@1
|
637 'operations' => $operations, |
webmaster@1
|
638 'finished' => '_install_profile_batch_finished', |
webmaster@1
|
639 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_name())), |
webmaster@1
|
640 'error_message' => st('The installation has encountered an error.'), |
webmaster@1
|
641 ); |
webmaster@1
|
642 // Start a batch, switch to 'profile-install-batch' task. We need to |
webmaster@1
|
643 // set the variable here, because batch_process() redirects. |
webmaster@1
|
644 variable_set('install_task', 'profile-install-batch'); |
webmaster@1
|
645 batch_set($batch); |
webmaster@1
|
646 batch_process($url, $url); |
webmaster@1
|
647 } |
webmaster@1
|
648 // We are running a batch install of the profile's modules. |
webmaster@1
|
649 // This might run in multiple HTTP requests, constantly redirecting |
webmaster@1
|
650 // to the same address, until the batch finished callback is invoked |
webmaster@1
|
651 // and the task advances to 'locale-initial-import'. |
webmaster@1
|
652 if ($task == 'profile-install-batch') { |
webmaster@1
|
653 include_once 'includes/batch.inc'; |
webmaster@1
|
654 $output = _batch_page(); |
webmaster@1
|
655 } |
webmaster@1
|
656 |
webmaster@1
|
657 // Import interface translations for the enabled modules. |
webmaster@1
|
658 if ($task == 'locale-initial-import') { |
webmaster@1
|
659 if (!empty($install_locale) && ($install_locale != 'en')) { |
webmaster@1
|
660 include_once 'includes/locale.inc'; |
webmaster@1
|
661 // Enable installation language as default site language. |
webmaster@1
|
662 locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE); |
webmaster@1
|
663 // Collect files to import for this language. |
webmaster@1
|
664 $batch = locale_batch_by_language($install_locale, '_install_locale_initial_batch_finished'); |
webmaster@1
|
665 if (!empty($batch)) { |
webmaster@1
|
666 // Remember components we cover in this batch set. |
webmaster@1
|
667 variable_set('install_locale_batch_components', $batch['#components']); |
webmaster@1
|
668 // Start a batch, switch to 'locale-batch' task. We need to |
webmaster@1
|
669 // set the variable here, because batch_process() redirects. |
webmaster@1
|
670 variable_set('install_task', 'locale-initial-batch'); |
webmaster@1
|
671 batch_set($batch); |
webmaster@1
|
672 batch_process($url, $url); |
webmaster@1
|
673 } |
webmaster@1
|
674 } |
webmaster@1
|
675 // Found nothing to import or not foreign language, go to next task. |
webmaster@1
|
676 $task = 'configure'; |
webmaster@1
|
677 } |
webmaster@1
|
678 if ($task == 'locale-initial-batch') { |
webmaster@1
|
679 include_once 'includes/batch.inc'; |
webmaster@1
|
680 include_once 'includes/locale.inc'; |
webmaster@1
|
681 $output = _batch_page(); |
webmaster@1
|
682 } |
webmaster@1
|
683 |
webmaster@1
|
684 if ($task == 'configure') { |
webmaster@1
|
685 if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) { |
webmaster@1
|
686 // Site already configured: This should never happen, means re-running |
webmaster@1
|
687 // the installer, possibly by an attacker after the 'install_task' variable |
webmaster@1
|
688 // got accidentally blown somewhere. Stop it now. |
webmaster@1
|
689 install_already_done_error(); |
webmaster@1
|
690 } |
webmaster@1
|
691 $form = drupal_get_form('install_configure_form', $url); |
webmaster@1
|
692 |
webmaster@1
|
693 if (!variable_get('site_name', FALSE) && !variable_get('site_mail', FALSE)) { |
webmaster@1
|
694 // Not submitted yet: Prepare to display the form. |
webmaster@1
|
695 $output = $form; |
webmaster@1
|
696 drupal_set_title(st('Configure site')); |
webmaster@1
|
697 |
webmaster@1
|
698 // Warn about settings.php permissions risk |
webmaster@1
|
699 $settings_dir = './'. conf_path(); |
webmaster@1
|
700 $settings_file = $settings_dir .'/settings.php'; |
webmaster@1
|
701 if (!drupal_verify_install_file($settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) { |
webmaster@1
|
702 drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, please consult the <a href="@handbook_url">on-line handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/getting-started')), 'error'); |
webmaster@1
|
703 } |
webmaster@1
|
704 else { |
webmaster@1
|
705 drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file))); |
webmaster@1
|
706 } |
webmaster@1
|
707 |
webmaster@1
|
708 // Add JavaScript validation. |
webmaster@1
|
709 _user_password_dynamic_validation(); |
webmaster@1
|
710 drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); |
webmaster@1
|
711 // We add these strings as settings because JavaScript translation does not |
webmaster@1
|
712 // work on install time. |
webmaster@1
|
713 drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')), 'cleanURL' => array('success' => st('Your server has been successfully tested to support this feature.'), 'failure' => st('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.'), 'testing' => st('Testing clean URLs...'))), 'setting'); |
webmaster@1
|
714 drupal_add_js(' |
webmaster@1
|
715 // Global Killswitch |
webmaster@1
|
716 if (Drupal.jsEnabled) { |
webmaster@1
|
717 $(document).ready(function() { |
webmaster@1
|
718 Drupal.cleanURLsInstallCheck(); |
webmaster@1
|
719 Drupal.setDefaultTimezone(); |
webmaster@1
|
720 }); |
webmaster@1
|
721 }', 'inline'); |
webmaster@1
|
722 // Build menu to allow clean URL check. |
webmaster@1
|
723 menu_rebuild(); |
webmaster@1
|
724 } |
webmaster@1
|
725 |
webmaster@1
|
726 else { |
webmaster@1
|
727 $task = 'profile'; |
webmaster@1
|
728 } |
webmaster@1
|
729 } |
webmaster@1
|
730 |
webmaster@1
|
731 // If found an unknown task or the 'profile' task, which is |
webmaster@1
|
732 // reserved for profiles, hand over the control to the profile, |
webmaster@1
|
733 // so it can run any number of custom tasks it defines. |
webmaster@1
|
734 if (!in_array($task, install_reserved_tasks())) { |
webmaster@1
|
735 $function = $profile .'_profile_tasks'; |
webmaster@1
|
736 if (function_exists($function)) { |
webmaster@1
|
737 // The profile needs to run more code, maybe even more tasks. |
webmaster@1
|
738 // $task is sent through as a reference and may be changed! |
webmaster@1
|
739 $output = $function($task, $url); |
webmaster@1
|
740 } |
webmaster@1
|
741 |
webmaster@1
|
742 // If the profile doesn't move on to a new task we assume |
webmaster@1
|
743 // that it is done. |
webmaster@1
|
744 if ($task == 'profile') { |
webmaster@1
|
745 $task = 'profile-finished'; |
webmaster@1
|
746 } |
webmaster@1
|
747 } |
webmaster@1
|
748 |
webmaster@1
|
749 // Profile custom tasks are done, so let the installer regain |
webmaster@1
|
750 // control and proceed with importing the remaining translations. |
webmaster@1
|
751 if ($task == 'profile-finished') { |
webmaster@1
|
752 if (!empty($install_locale) && ($install_locale != 'en')) { |
webmaster@1
|
753 include_once 'includes/locale.inc'; |
webmaster@1
|
754 // Collect files to import for this language. Skip components |
webmaster@1
|
755 // already covered in the initial batch set. |
webmaster@1
|
756 $batch = locale_batch_by_language($install_locale, '_install_locale_remaining_batch_finished', variable_get('install_locale_batch_components', array())); |
webmaster@1
|
757 // Remove temporary variable. |
webmaster@1
|
758 variable_del('install_locale_batch_components'); |
webmaster@1
|
759 if (!empty($batch)) { |
webmaster@1
|
760 // Start a batch, switch to 'locale-remaining-batch' task. We need to |
webmaster@1
|
761 // set the variable here, because batch_process() redirects. |
webmaster@1
|
762 variable_set('install_task', 'locale-remaining-batch'); |
webmaster@1
|
763 batch_set($batch); |
webmaster@1
|
764 batch_process($url, $url); |
webmaster@1
|
765 } |
webmaster@1
|
766 } |
webmaster@1
|
767 // Found nothing to import or not foreign language, go to next task. |
webmaster@1
|
768 $task = 'finished'; |
webmaster@1
|
769 } |
webmaster@1
|
770 if ($task == 'locale-remaining-batch') { |
webmaster@1
|
771 include_once 'includes/batch.inc'; |
webmaster@1
|
772 include_once 'includes/locale.inc'; |
webmaster@1
|
773 $output = _batch_page(); |
webmaster@1
|
774 } |
webmaster@1
|
775 |
webmaster@1
|
776 // Display a 'finished' page to user. |
webmaster@1
|
777 if ($task == 'finished') { |
webmaster@1
|
778 drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name()))); |
webmaster@1
|
779 $messages = drupal_set_message(); |
webmaster@1
|
780 $output = '<p>'. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'</p>'; |
webmaster@1
|
781 $output .= '<p>'. (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) .'</p>'; |
webmaster@1
|
782 $task = 'done'; |
webmaster@1
|
783 } |
webmaster@1
|
784 |
webmaster@1
|
785 // The end of the install process. Remember profile used. |
webmaster@1
|
786 if ($task == 'done') { |
webmaster@1
|
787 // Rebuild menu to get content type links registered by the profile, |
webmaster@1
|
788 // and possibly any other menu items created through the tasks. |
webmaster@1
|
789 menu_rebuild(); |
webmaster@1
|
790 |
webmaster@1
|
791 // Register actions declared by any modules. |
webmaster@1
|
792 actions_synchronize(); |
webmaster@1
|
793 |
webmaster@1
|
794 // Randomize query-strings on css/js files, to hide the fact that |
webmaster@1
|
795 // this is a new install, not upgraded yet. |
webmaster@1
|
796 _drupal_flush_css_js(); |
webmaster@1
|
797 |
webmaster@1
|
798 variable_set('install_profile', $profile); |
webmaster@1
|
799 } |
webmaster@1
|
800 |
webmaster@1
|
801 // Set task for user, and remember the task in the database. |
webmaster@1
|
802 install_task_list($task); |
webmaster@1
|
803 variable_set('install_task', $task); |
webmaster@1
|
804 |
webmaster@1
|
805 // Output page, if some output was required. Otherwise it is possible |
webmaster@1
|
806 // that we are printing a JSON page and theme output should not be there. |
webmaster@1
|
807 if (isset($output)) { |
webmaster@1
|
808 print theme('maintenance_page', $output); |
webmaster@1
|
809 } |
webmaster@1
|
810 } |
webmaster@1
|
811 |
webmaster@1
|
812 /** |
webmaster@1
|
813 * Batch callback for batch installation of modules. |
webmaster@1
|
814 */ |
webmaster@1
|
815 function _install_module_batch($module, $module_name, &$context) { |
webmaster@1
|
816 _drupal_install_module($module); |
webmaster@1
|
817 // We enable the installed module right away, so that the module will be |
webmaster@1
|
818 // loaded by drupal_bootstrap in subsequent batch requests, and other |
webmaster@1
|
819 // modules possibly depending on it can safely perform their installation |
webmaster@1
|
820 // steps. |
webmaster@1
|
821 module_enable(array($module)); |
webmaster@1
|
822 $context['results'][] = $module; |
webmaster@1
|
823 $context['message'] = 'Installed '. $module_name .' module.'; |
webmaster@1
|
824 } |
webmaster@1
|
825 |
webmaster@1
|
826 /** |
webmaster@1
|
827 * Finished callback for the modules install batch. |
webmaster@1
|
828 * |
webmaster@1
|
829 * Advance installer task to language import. |
webmaster@1
|
830 */ |
webmaster@1
|
831 function _install_profile_batch_finished($success, $results) { |
webmaster@1
|
832 variable_set('install_task', 'locale-initial-import'); |
webmaster@1
|
833 } |
webmaster@1
|
834 |
webmaster@1
|
835 /** |
webmaster@1
|
836 * Finished callback for the first locale import batch. |
webmaster@1
|
837 * |
webmaster@1
|
838 * Advance installer task to the configure screen. |
webmaster@1
|
839 */ |
webmaster@1
|
840 function _install_locale_initial_batch_finished($success, $results) { |
webmaster@1
|
841 variable_set('install_task', 'configure'); |
webmaster@1
|
842 } |
webmaster@1
|
843 |
webmaster@1
|
844 /** |
webmaster@1
|
845 * Finished callback for the second locale import batch. |
webmaster@1
|
846 * |
webmaster@1
|
847 * Advance installer task to the finished screen. |
webmaster@1
|
848 */ |
webmaster@1
|
849 function _install_locale_remaining_batch_finished($success, $results) { |
webmaster@1
|
850 variable_set('install_task', 'finished'); |
webmaster@1
|
851 } |
webmaster@1
|
852 |
webmaster@1
|
853 /** |
webmaster@1
|
854 * The list of reserved tasks to run in the installer. |
webmaster@1
|
855 */ |
webmaster@1
|
856 function install_reserved_tasks() { |
webmaster@1
|
857 return array('configure', 'profile-install', 'profile-install-batch', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done'); |
webmaster@1
|
858 } |
webmaster@1
|
859 |
webmaster@1
|
860 /** |
webmaster@1
|
861 * Check installation requirements and report any errors. |
webmaster@1
|
862 */ |
webmaster@1
|
863 function install_check_requirements($profile, $verify) { |
webmaster@1
|
864 |
webmaster@1
|
865 // If Drupal is not set up already, we need to create a settings file. |
webmaster@1
|
866 if (!$verify) { |
webmaster@1
|
867 $writable = FALSE; |
webmaster@1
|
868 $conf_path = './'. conf_path(FALSE, TRUE); |
webmaster@1
|
869 $settings_file = $conf_path .'/settings.php'; |
webmaster@1
|
870 $file = $conf_path; |
webmaster@7
|
871 $exists = FALSE; |
webmaster@1
|
872 // Verify that the directory exists. |
webmaster@1
|
873 if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) { |
webmaster@7
|
874 // Check to make sure a settings.php already exists. |
webmaster@7
|
875 $file = $settings_file; |
webmaster@1
|
876 if (drupal_verify_install_file($settings_file, FILE_EXIST)) { |
webmaster@7
|
877 $exists = TRUE; |
webmaster@1
|
878 // If it does, make sure it is writable. |
webmaster@1
|
879 $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE); |
webmaster@1
|
880 } |
webmaster@1
|
881 } |
webmaster@7
|
882 if (!$exists) { |
webmaster@7
|
883 drupal_set_message(st('The @drupal installer requires that you create %file as part of the installation process, and then make it writable. If you are unsure how to grant file permissions, please consult the <a href="@handbook_url">on-line handbook</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'error'); |
webmaster@7
|
884 } |
webmaster@7
|
885 elseif (!$writable) { |
webmaster@1
|
886 drupal_set_message(st('The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, please consult the <a href="@handbook_url">on-line handbook</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'error'); |
webmaster@1
|
887 } |
webmaster@1
|
888 } |
webmaster@1
|
889 |
webmaster@1
|
890 // Check the other requirements. |
webmaster@1
|
891 $requirements = drupal_check_profile($profile); |
webmaster@1
|
892 $severity = drupal_requirements_severity($requirements); |
webmaster@1
|
893 |
webmaster@1
|
894 // If there are issues, report them. |
webmaster@1
|
895 if ($severity == REQUIREMENT_ERROR) { |
webmaster@1
|
896 |
webmaster@1
|
897 foreach ($requirements as $requirement) { |
webmaster@1
|
898 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) { |
webmaster@1
|
899 $message = $requirement['description']; |
webmaster@1
|
900 if (isset($requirement['value']) && $requirement['value']) { |
webmaster@1
|
901 $message .= ' ('. st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) .')'; |
webmaster@1
|
902 } |
webmaster@1
|
903 drupal_set_message($message, 'error'); |
webmaster@1
|
904 } |
webmaster@1
|
905 } |
webmaster@1
|
906 } |
webmaster@1
|
907 if ($severity == REQUIREMENT_WARNING) { |
webmaster@1
|
908 |
webmaster@1
|
909 foreach ($requirements as $requirement) { |
webmaster@1
|
910 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_WARNING) { |
webmaster@1
|
911 $message = $requirement['description']; |
webmaster@1
|
912 if (isset($requirement['value']) && $requirement['value']) { |
webmaster@1
|
913 $message .= ' ('. st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) .')'; |
webmaster@1
|
914 } |
webmaster@1
|
915 drupal_set_message($message, 'warning'); |
webmaster@1
|
916 } |
webmaster@1
|
917 } |
webmaster@1
|
918 } |
webmaster@1
|
919 } |
webmaster@1
|
920 |
webmaster@1
|
921 /** |
webmaster@1
|
922 * Add the installation task list to the current page. |
webmaster@1
|
923 */ |
webmaster@1
|
924 function install_task_list($active = NULL) { |
webmaster@1
|
925 // Default list of tasks. |
webmaster@1
|
926 $tasks = array( |
webmaster@1
|
927 'profile-select' => st('Choose profile'), |
webmaster@1
|
928 'locale-select' => st('Choose language'), |
webmaster@1
|
929 'requirements' => st('Verify requirements'), |
webmaster@1
|
930 'database' => st('Set up database'), |
webmaster@1
|
931 'profile-install-batch' => st('Install profile'), |
webmaster@1
|
932 'locale-initial-batch' => st('Set up translations'), |
webmaster@1
|
933 'configure' => st('Configure site'), |
webmaster@1
|
934 ); |
webmaster@1
|
935 |
webmaster@1
|
936 $profiles = install_find_profiles(); |
webmaster@1
|
937 $profile = isset($_GET['profile']) && isset($profiles[$_GET['profile']]) ? $_GET['profile'] : '.'; |
webmaster@1
|
938 $locales = install_find_locales($profile); |
webmaster@1
|
939 |
webmaster@1
|
940 // If we have only one profile, remove 'Choose profile' |
webmaster@1
|
941 // and rename 'Install profile'. |
webmaster@1
|
942 if (count($profiles) == 1) { |
webmaster@1
|
943 unset($tasks['profile-select']); |
webmaster@1
|
944 $tasks['profile-install-batch'] = st('Install site'); |
webmaster@1
|
945 } |
webmaster@1
|
946 |
webmaster@1
|
947 // Add tasks defined by the profile. |
webmaster@1
|
948 if ($profile) { |
webmaster@1
|
949 $function = $profile .'_profile_task_list'; |
webmaster@1
|
950 if (function_exists($function)) { |
webmaster@1
|
951 $result = $function(); |
webmaster@1
|
952 if (is_array($result)) { |
webmaster@1
|
953 $tasks += $result; |
webmaster@1
|
954 } |
webmaster@1
|
955 } |
webmaster@1
|
956 } |
webmaster@1
|
957 |
webmaster@1
|
958 if (count($locales) < 2 || empty($_GET['locale']) || $_GET['locale'] == 'en') { |
webmaster@1
|
959 // If not required, remove translation import from the task list. |
webmaster@1
|
960 unset($tasks['locale-initial-batch']); |
webmaster@1
|
961 } |
webmaster@1
|
962 else { |
webmaster@1
|
963 // If required, add remaining translations import task. |
webmaster@1
|
964 $tasks += array('locale-remaining-batch' => st('Finish translations')); |
webmaster@1
|
965 } |
webmaster@1
|
966 |
webmaster@1
|
967 // Add finished step as the last task. |
webmaster@1
|
968 $tasks += array( |
webmaster@1
|
969 'finished' => st('Finished') |
webmaster@1
|
970 ); |
webmaster@1
|
971 |
webmaster@1
|
972 // Let the theming function know that 'finished' and 'done' |
webmaster@1
|
973 // include everything, so every step is completed. |
webmaster@1
|
974 if (in_array($active, array('finished', 'done'))) { |
webmaster@1
|
975 $active = NULL; |
webmaster@1
|
976 } |
webmaster@1
|
977 drupal_set_content('left', theme_task_list($tasks, $active)); |
webmaster@1
|
978 } |
webmaster@1
|
979 |
webmaster@1
|
980 /** |
webmaster@1
|
981 * Form API array definition for site configuration. |
webmaster@1
|
982 */ |
webmaster@1
|
983 function install_configure_form(&$form_state, $url) { |
webmaster@1
|
984 |
webmaster@1
|
985 $form['intro'] = array( |
webmaster@1
|
986 '#value' => st('To configure your website, please provide the following information.'), |
webmaster@1
|
987 '#weight' => -10, |
webmaster@1
|
988 ); |
webmaster@1
|
989 $form['site_information'] = array( |
webmaster@1
|
990 '#type' => 'fieldset', |
webmaster@1
|
991 '#title' => st('Site information'), |
webmaster@1
|
992 '#collapsible' => FALSE, |
webmaster@1
|
993 ); |
webmaster@1
|
994 $form['site_information']['site_name'] = array( |
webmaster@1
|
995 '#type' => 'textfield', |
webmaster@1
|
996 '#title' => st('Site name'), |
webmaster@1
|
997 '#required' => TRUE, |
webmaster@1
|
998 '#weight' => -20, |
webmaster@1
|
999 ); |
webmaster@1
|
1000 $form['site_information']['site_mail'] = array( |
webmaster@1
|
1001 '#type' => 'textfield', |
webmaster@1
|
1002 '#title' => st('Site e-mail address'), |
webmaster@1
|
1003 '#default_value' => ini_get('sendmail_from'), |
webmaster@1
|
1004 '#description' => st("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"), |
webmaster@1
|
1005 '#required' => TRUE, |
webmaster@1
|
1006 '#weight' => -15, |
webmaster@1
|
1007 ); |
webmaster@1
|
1008 $form['admin_account'] = array( |
webmaster@1
|
1009 '#type' => 'fieldset', |
webmaster@1
|
1010 '#title' => st('Administrator account'), |
webmaster@1
|
1011 '#collapsible' => FALSE, |
webmaster@1
|
1012 ); |
webmaster@1
|
1013 $form['admin_account']['account']['#tree'] = TRUE; |
webmaster@1
|
1014 $form['admin_account']['markup'] = array( |
webmaster@1
|
1015 '#value' => '<p class="description">'. st('The administrator account has complete access to the site; it will automatically be granted all permissions and can perform any administrative activity. This will be the only account that can perform certain activities, so keep its credentials safe.') .'</p>', |
webmaster@1
|
1016 '#weight' => -10, |
webmaster@1
|
1017 ); |
webmaster@1
|
1018 |
webmaster@1
|
1019 $form['admin_account']['account']['name'] = array('#type' => 'textfield', |
webmaster@1
|
1020 '#title' => st('Username'), |
webmaster@1
|
1021 '#maxlength' => USERNAME_MAX_LENGTH, |
webmaster@1
|
1022 '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), |
webmaster@1
|
1023 '#required' => TRUE, |
webmaster@1
|
1024 '#weight' => -10, |
webmaster@1
|
1025 ); |
webmaster@1
|
1026 |
webmaster@1
|
1027 $form['admin_account']['account']['mail'] = array('#type' => 'textfield', |
webmaster@1
|
1028 '#title' => st('E-mail address'), |
webmaster@1
|
1029 '#maxlength' => EMAIL_MAX_LENGTH, |
webmaster@1
|
1030 '#description' => st('All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), |
webmaster@1
|
1031 '#required' => TRUE, |
webmaster@1
|
1032 '#weight' => -5, |
webmaster@1
|
1033 ); |
webmaster@1
|
1034 $form['admin_account']['account']['pass'] = array( |
webmaster@1
|
1035 '#type' => 'password_confirm', |
webmaster@1
|
1036 '#required' => TRUE, |
webmaster@1
|
1037 '#size' => 25, |
webmaster@1
|
1038 '#weight' => 0, |
webmaster@1
|
1039 ); |
webmaster@1
|
1040 |
webmaster@1
|
1041 $form['server_settings'] = array( |
webmaster@1
|
1042 '#type' => 'fieldset', |
webmaster@1
|
1043 '#title' => st('Server settings'), |
webmaster@1
|
1044 '#collapsible' => FALSE, |
webmaster@1
|
1045 ); |
webmaster@1
|
1046 $form['server_settings']['date_default_timezone'] = array( |
webmaster@1
|
1047 '#type' => 'select', |
webmaster@1
|
1048 '#title' => st('Default time zone'), |
webmaster@1
|
1049 '#default_value' => 0, |
webmaster@1
|
1050 '#options' => _system_zonelist(), |
webmaster@1
|
1051 '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'), |
webmaster@1
|
1052 '#weight' => 5, |
webmaster@1
|
1053 ); |
webmaster@1
|
1054 |
webmaster@1
|
1055 $form['server_settings']['clean_url'] = array( |
webmaster@1
|
1056 '#type' => 'radios', |
webmaster@1
|
1057 '#title' => st('Clean URLs'), |
webmaster@1
|
1058 '#default_value' => 0, |
webmaster@1
|
1059 '#options' => array(0 => st('Disabled'), 1 => st('Enabled')), |
webmaster@1
|
1060 '#description' => st('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL).'), |
webmaster@1
|
1061 '#disabled' => TRUE, |
webmaster@1
|
1062 '#prefix' => '<div id="clean-url" class="install">', |
webmaster@1
|
1063 '#suffix' => '</div>', |
webmaster@1
|
1064 '#weight' => 10, |
webmaster@1
|
1065 ); |
webmaster@1
|
1066 |
webmaster@1
|
1067 $form['server_settings']['update_status_module'] = array( |
webmaster@1
|
1068 '#type' => 'checkboxes', |
webmaster@1
|
1069 '#title' => st('Update notifications'), |
webmaster@1
|
1070 '#options' => array(1 => st('Check for updates automatically')), |
webmaster@1
|
1071 '#default_value' => array(1), |
webmaster@1
|
1072 '#description' => st('With this option enabled, Drupal will notify you when new releases are available. This will significantly enhance your site\'s security and is <strong>highly recommended</strong>. This requires your site to periodically send anonymous information on its installed components to <a href="@drupal">drupal.org</a>. For more information please see the <a href="@update">update notification information</a>.', array('@drupal' => 'http://drupal.org', '@update' => 'http://drupal.org/handbook/modules/update')), |
webmaster@1
|
1073 '#weight' => 15, |
webmaster@1
|
1074 ); |
webmaster@1
|
1075 |
webmaster@1
|
1076 $form['submit'] = array( |
webmaster@1
|
1077 '#type' => 'submit', |
webmaster@1
|
1078 '#value' => st('Save and continue'), |
webmaster@1
|
1079 '#weight' => 15, |
webmaster@1
|
1080 ); |
webmaster@1
|
1081 $form['#action'] = $url; |
webmaster@1
|
1082 $form['#redirect'] = FALSE; |
webmaster@1
|
1083 |
webmaster@1
|
1084 // Allow the profile to alter this form. $form_state isn't available |
webmaster@1
|
1085 // here, but to conform to the hook_form_alter() signature, we pass |
webmaster@1
|
1086 // an empty array. |
webmaster@1
|
1087 $hook_form_alter = $_GET['profile'] .'_form_alter'; |
webmaster@1
|
1088 if (function_exists($hook_form_alter)) { |
webmaster@1
|
1089 $hook_form_alter($form, array(), 'install_configure'); |
webmaster@1
|
1090 } |
webmaster@1
|
1091 return $form; |
webmaster@1
|
1092 } |
webmaster@1
|
1093 |
webmaster@1
|
1094 /** |
webmaster@1
|
1095 * Form API validate for the site configuration form. |
webmaster@1
|
1096 */ |
webmaster@1
|
1097 function install_configure_form_validate($form, &$form_state) { |
webmaster@1
|
1098 if ($error = user_validate_name($form_state['values']['account']['name'])) { |
webmaster@1
|
1099 form_error($form['admin_account']['account']['name'], $error); |
webmaster@1
|
1100 } |
webmaster@1
|
1101 if ($error = user_validate_mail($form_state['values']['account']['mail'])) { |
webmaster@1
|
1102 form_error($form['admin_account']['account']['mail'], $error); |
webmaster@1
|
1103 } |
webmaster@1
|
1104 if ($error = user_validate_mail($form_state['values']['site_mail'])) { |
webmaster@1
|
1105 form_error($form['site_information']['site_mail'], $error); |
webmaster@1
|
1106 } |
webmaster@1
|
1107 } |
webmaster@1
|
1108 |
webmaster@1
|
1109 /** |
webmaster@1
|
1110 * Form API submit for the site configuration form. |
webmaster@1
|
1111 */ |
webmaster@1
|
1112 function install_configure_form_submit($form, &$form_state) { |
webmaster@1
|
1113 global $user; |
webmaster@1
|
1114 |
webmaster@1
|
1115 variable_set('site_name', $form_state['values']['site_name']); |
webmaster@1
|
1116 variable_set('site_mail', $form_state['values']['site_mail']); |
webmaster@1
|
1117 variable_set('date_default_timezone', $form_state['values']['date_default_timezone']); |
webmaster@1
|
1118 |
webmaster@1
|
1119 // Enable update.module if this option was selected. |
webmaster@1
|
1120 if ($form_state['values']['update_status_module'][1]) { |
webmaster@1
|
1121 drupal_install_modules(array('update')); |
webmaster@1
|
1122 } |
webmaster@1
|
1123 |
webmaster@1
|
1124 // Turn this off temporarily so that we can pass a password through. |
webmaster@1
|
1125 variable_set('user_email_verification', FALSE); |
webmaster@1
|
1126 $form_state['old_values'] = $form_state['values']; |
webmaster@1
|
1127 $form_state['values'] = $form_state['values']['account']; |
webmaster@1
|
1128 |
webmaster@1
|
1129 // We precreated user 1 with placeholder values. Let's save the real values. |
webmaster@1
|
1130 $account = user_load(1); |
webmaster@1
|
1131 $merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 1); |
webmaster@1
|
1132 user_save($account, array_merge($form_state['values'], $merge_data)); |
webmaster@1
|
1133 // Log in the first user. |
webmaster@1
|
1134 user_authenticate($form_state['values']); |
webmaster@1
|
1135 $form_state['values'] = $form_state['old_values']; |
webmaster@1
|
1136 unset($form_state['old_values']); |
webmaster@1
|
1137 variable_set('user_email_verification', TRUE); |
webmaster@1
|
1138 |
webmaster@1
|
1139 if (isset($form_state['values']['clean_url'])) { |
webmaster@1
|
1140 variable_set('clean_url', $form_state['values']['clean_url']); |
webmaster@1
|
1141 } |
webmaster@1
|
1142 // The user is now logged in, but has no session ID yet, which |
webmaster@1
|
1143 // would be required later in the request, so remember it. |
webmaster@1
|
1144 $user->sid = session_id(); |
webmaster@1
|
1145 |
webmaster@1
|
1146 // Record when this install ran. |
webmaster@1
|
1147 variable_set('install_time', time()); |
webmaster@1
|
1148 } |
webmaster@1
|
1149 |
webmaster@1
|
1150 // Start the installer. |
webmaster@1
|
1151 install_main(); |