source: sipes/cord/install.php @ 669aaf1

stableversion-3.0
Last change on this file since 669aaf1 was d7a822e, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio del cord

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