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