annotate includes/install.core.inc @ 13:134d4b2e75f6

updated quicktabs and google analytics modules
author danieleb <danielebarchiesi@me.com>
date Tue, 29 Oct 2013 13:48:59 +0000
parents ff03f76ab3fe
children
rev   line source
danielebarchiesi@0 1 <?php
danielebarchiesi@0 2
danielebarchiesi@0 3 /**
danielebarchiesi@0 4 * @file
danielebarchiesi@0 5 * API functions for installing Drupal.
danielebarchiesi@0 6 */
danielebarchiesi@0 7
danielebarchiesi@0 8 /**
danielebarchiesi@0 9 * Do not run the task during the current installation request.
danielebarchiesi@0 10 *
danielebarchiesi@0 11 * This can be used to skip running an installation task when certain
danielebarchiesi@0 12 * conditions are met, even though the task may still show on the list of
danielebarchiesi@0 13 * installation tasks presented to the user. For example, the Drupal installer
danielebarchiesi@0 14 * uses this flag to skip over the database configuration form when valid
danielebarchiesi@0 15 * database connection information is already available from settings.php. It
danielebarchiesi@0 16 * also uses this flag to skip language import tasks when the installation is
danielebarchiesi@0 17 * being performed in English.
danielebarchiesi@0 18 */
danielebarchiesi@0 19 define('INSTALL_TASK_SKIP', 1);
danielebarchiesi@0 20
danielebarchiesi@0 21 /**
danielebarchiesi@0 22 * Run the task on each installation request until the database is set up.
danielebarchiesi@0 23 *
danielebarchiesi@0 24 * This is primarily used by the Drupal installer for bootstrap-related tasks.
danielebarchiesi@0 25 */
danielebarchiesi@0 26 define('INSTALL_TASK_RUN_IF_REACHED', 2);
danielebarchiesi@0 27
danielebarchiesi@0 28 /**
danielebarchiesi@0 29 * Global flag to indicate that a task should be run on each installation
danielebarchiesi@0 30 * request that reaches it, until the database is set up and we are able to
danielebarchiesi@0 31 * record the fact that it already ran.
danielebarchiesi@0 32 *
danielebarchiesi@0 33 * This is the default method for running tasks and should be used for most
danielebarchiesi@0 34 * tasks that occur after the database is set up; these tasks will then run
danielebarchiesi@0 35 * once and be marked complete once they are successfully finished. For
danielebarchiesi@0 36 * example, the Drupal installer uses this flag for the batch installation of
danielebarchiesi@0 37 * modules on the new site, and also for the configuration form that collects
danielebarchiesi@0 38 * basic site information and sets up the site maintenance account.
danielebarchiesi@0 39 */
danielebarchiesi@0 40 define('INSTALL_TASK_RUN_IF_NOT_COMPLETED', 3);
danielebarchiesi@0 41
danielebarchiesi@0 42 /**
danielebarchiesi@0 43 * Installs Drupal either interactively or via an array of passed-in settings.
danielebarchiesi@0 44 *
danielebarchiesi@0 45 * The Drupal installation happens in a series of steps, which may be spread
danielebarchiesi@0 46 * out over multiple page requests. Each request begins by trying to determine
danielebarchiesi@0 47 * the last completed installation step (also known as a "task"), if one is
danielebarchiesi@0 48 * available from a previous request. Control is then passed to the task
danielebarchiesi@0 49 * handler, which processes the remaining tasks that need to be run until (a)
danielebarchiesi@0 50 * an error is thrown, (b) a new page needs to be displayed, or (c) the
danielebarchiesi@0 51 * installation finishes (whichever happens first).
danielebarchiesi@0 52 *
danielebarchiesi@0 53 * @param $settings
danielebarchiesi@0 54 * An optional array of installation settings. Leave this empty for a normal,
danielebarchiesi@0 55 * interactive, browser-based installation intended to occur over multiple
danielebarchiesi@0 56 * page requests. Alternatively, if an array of settings is passed in, the
danielebarchiesi@0 57 * installer will attempt to use it to perform the installation in a single
danielebarchiesi@0 58 * page request (optimized for the command line) and not send any output
danielebarchiesi@0 59 * intended for the web browser. See install_state_defaults() for a list of
danielebarchiesi@0 60 * elements that are allowed to appear in this array.
danielebarchiesi@0 61 *
danielebarchiesi@0 62 * @see install_state_defaults()
danielebarchiesi@0 63 */
danielebarchiesi@0 64 function install_drupal($settings = array()) {
danielebarchiesi@0 65 global $install_state;
danielebarchiesi@0 66 // Initialize the installation state with the settings that were passed in,
danielebarchiesi@0 67 // as well as a boolean indicating whether or not this is an interactive
danielebarchiesi@0 68 // installation.
danielebarchiesi@0 69 $interactive = empty($settings);
danielebarchiesi@0 70 $install_state = $settings + array('interactive' => $interactive) + install_state_defaults();
danielebarchiesi@0 71 try {
danielebarchiesi@0 72 // Begin the page request. This adds information about the current state of
danielebarchiesi@0 73 // the Drupal installation to the passed-in array.
danielebarchiesi@0 74 install_begin_request($install_state);
danielebarchiesi@0 75 // Based on the installation state, run the remaining tasks for this page
danielebarchiesi@0 76 // request, and collect any output.
danielebarchiesi@0 77 $output = install_run_tasks($install_state);
danielebarchiesi@0 78 }
danielebarchiesi@0 79 catch (Exception $e) {
danielebarchiesi@0 80 // When an installation error occurs, either send the error to the web
danielebarchiesi@0 81 // browser or pass on the exception so the calling script can use it.
danielebarchiesi@0 82 if ($install_state['interactive']) {
danielebarchiesi@0 83 install_display_output($e->getMessage(), $install_state);
danielebarchiesi@0 84 }
danielebarchiesi@0 85 else {
danielebarchiesi@0 86 throw $e;
danielebarchiesi@0 87 }
danielebarchiesi@0 88 }
danielebarchiesi@0 89 // All available tasks for this page request are now complete. Interactive
danielebarchiesi@0 90 // installations can send output to the browser or redirect the user to the
danielebarchiesi@0 91 // next page.
danielebarchiesi@0 92 if ($install_state['interactive']) {
danielebarchiesi@0 93 if ($install_state['parameters_changed']) {
danielebarchiesi@0 94 // Redirect to the correct page if the URL parameters have changed.
danielebarchiesi@0 95 install_goto(install_redirect_url($install_state));
danielebarchiesi@0 96 }
danielebarchiesi@0 97 elseif (isset($output)) {
danielebarchiesi@0 98 // Display a page only if some output is available. Otherwise it is
danielebarchiesi@0 99 // possible that we are printing a JSON page and theme output should
danielebarchiesi@0 100 // not be shown.
danielebarchiesi@0 101 install_display_output($output, $install_state);
danielebarchiesi@0 102 }
danielebarchiesi@0 103 }
danielebarchiesi@0 104 }
danielebarchiesi@0 105
danielebarchiesi@0 106 /**
danielebarchiesi@0 107 * Returns an array of default settings for the global installation state.
danielebarchiesi@0 108 *
danielebarchiesi@0 109 * The installation state is initialized with these settings at the beginning
danielebarchiesi@0 110 * of each page request. They may evolve during the page request, but they are
danielebarchiesi@0 111 * initialized again once the next request begins.
danielebarchiesi@0 112 *
danielebarchiesi@0 113 * Non-interactive Drupal installations can override some of these default
danielebarchiesi@0 114 * settings by passing in an array to the installation script, most notably
danielebarchiesi@0 115 * 'parameters' (which contains one-time parameters such as 'profile' and
danielebarchiesi@0 116 * 'locale' that are normally passed in via the URL) and 'forms' (which can
danielebarchiesi@0 117 * be used to programmatically submit forms during the installation; the keys
danielebarchiesi@0 118 * of each element indicate the name of the installation task that the form
danielebarchiesi@0 119 * submission is for, and the values are used as the $form_state['values']
danielebarchiesi@0 120 * array that is passed on to the form submission via drupal_form_submit()).
danielebarchiesi@0 121 *
danielebarchiesi@0 122 * @see drupal_form_submit()
danielebarchiesi@0 123 */
danielebarchiesi@0 124 function install_state_defaults() {
danielebarchiesi@0 125 $defaults = array(
danielebarchiesi@0 126 // The current task being processed.
danielebarchiesi@0 127 'active_task' => NULL,
danielebarchiesi@0 128 // The last task that was completed during the previous installation
danielebarchiesi@0 129 // request.
danielebarchiesi@0 130 'completed_task' => NULL,
danielebarchiesi@0 131 // This becomes TRUE only when Drupal's system module is installed.
danielebarchiesi@0 132 'database_tables_exist' => FALSE,
danielebarchiesi@0 133 // An array of forms to be programmatically submitted during the
danielebarchiesi@0 134 // installation. The keys of each element indicate the name of the
danielebarchiesi@0 135 // installation task that the form submission is for, and the values are
danielebarchiesi@0 136 // used as the $form_state['values'] array that is passed on to the form
danielebarchiesi@0 137 // submission via drupal_form_submit().
danielebarchiesi@0 138 'forms' => array(),
danielebarchiesi@0 139 // This becomes TRUE only at the end of the installation process, after
danielebarchiesi@0 140 // all available tasks have been completed and Drupal is fully installed.
danielebarchiesi@0 141 // It is used by the installer to store correct information in the database
danielebarchiesi@0 142 // about the completed installation, as well as to inform theme functions
danielebarchiesi@0 143 // that all tasks are finished (so that the task list can be displayed
danielebarchiesi@0 144 // correctly).
danielebarchiesi@0 145 'installation_finished' => FALSE,
danielebarchiesi@0 146 // Whether or not this installation is interactive. By default this will
danielebarchiesi@0 147 // be set to FALSE if settings are passed in to install_drupal().
danielebarchiesi@0 148 'interactive' => TRUE,
danielebarchiesi@0 149 // An array of available languages for the installation.
danielebarchiesi@0 150 'locales' => array(),
danielebarchiesi@0 151 // An array of parameters for the installation, pre-populated by the URL
danielebarchiesi@0 152 // or by the settings passed in to install_drupal(). This is primarily
danielebarchiesi@0 153 // used to store 'profile' (the name of the chosen installation profile)
danielebarchiesi@0 154 // and 'locale' (the name of the chosen installation language), since
danielebarchiesi@0 155 // these settings need to persist from page request to page request before
danielebarchiesi@0 156 // the database is available for storage.
danielebarchiesi@0 157 'parameters' => array(),
danielebarchiesi@0 158 // Whether or not the parameters have changed during the current page
danielebarchiesi@0 159 // request. For interactive installations, this will trigger a page
danielebarchiesi@0 160 // redirect.
danielebarchiesi@0 161 'parameters_changed' => FALSE,
danielebarchiesi@0 162 // An array of information about the chosen installation profile. This will
danielebarchiesi@0 163 // be filled in based on the profile's .info file.
danielebarchiesi@0 164 'profile_info' => array(),
danielebarchiesi@0 165 // An array of available installation profiles.
danielebarchiesi@0 166 'profiles' => array(),
danielebarchiesi@0 167 // An array of server variables that will be substituted into the global
danielebarchiesi@0 168 // $_SERVER array via drupal_override_server_variables(). Used by
danielebarchiesi@0 169 // non-interactive installations only.
danielebarchiesi@0 170 'server' => array(),
danielebarchiesi@0 171 // This becomes TRUE only when a valid database connection can be
danielebarchiesi@0 172 // established.
danielebarchiesi@0 173 'settings_verified' => FALSE,
danielebarchiesi@0 174 // Installation tasks can set this to TRUE to force the page request to
danielebarchiesi@0 175 // end (even if there is no themable output), in the case of an interactive
danielebarchiesi@0 176 // installation. This is needed only rarely; for example, it would be used
danielebarchiesi@0 177 // by an installation task that prints JSON output rather than returning a
danielebarchiesi@0 178 // themed page. The most common example of this is during batch processing,
danielebarchiesi@0 179 // but the Drupal installer automatically takes care of setting this
danielebarchiesi@0 180 // parameter properly in that case, so that individual installation tasks
danielebarchiesi@0 181 // which implement the batch API do not need to set it themselves.
danielebarchiesi@0 182 'stop_page_request' => FALSE,
danielebarchiesi@0 183 // Installation tasks can set this to TRUE to indicate that the task should
danielebarchiesi@0 184 // be run again, even if it normally wouldn't be. This can be used, for
danielebarchiesi@0 185 // example, if a single task needs to be spread out over multiple page
danielebarchiesi@0 186 // requests, or if it needs to perform some validation before allowing
danielebarchiesi@0 187 // itself to be marked complete. The most common examples of this are batch
danielebarchiesi@0 188 // processing and form submissions, but the Drupal installer automatically
danielebarchiesi@0 189 // takes care of setting this parameter properly in those cases, so that
danielebarchiesi@0 190 // individual installation tasks which implement the batch API or form API
danielebarchiesi@0 191 // do not need to set it themselves.
danielebarchiesi@0 192 'task_not_complete' => FALSE,
danielebarchiesi@0 193 // A list of installation tasks which have already been performed during
danielebarchiesi@0 194 // the current page request.
danielebarchiesi@0 195 'tasks_performed' => array(),
danielebarchiesi@0 196 );
danielebarchiesi@0 197 return $defaults;
danielebarchiesi@0 198 }
danielebarchiesi@0 199
danielebarchiesi@0 200 /**
danielebarchiesi@0 201 * Begins an installation request, modifying the installation state as needed.
danielebarchiesi@0 202 *
danielebarchiesi@0 203 * This function performs commands that must run at the beginning of every page
danielebarchiesi@0 204 * request. It throws an exception if the installation should not proceed.
danielebarchiesi@0 205 *
danielebarchiesi@0 206 * @param $install_state
danielebarchiesi@0 207 * An array of information about the current installation state. This is
danielebarchiesi@0 208 * modified with information gleaned from the beginning of the page request.
danielebarchiesi@0 209 */
danielebarchiesi@0 210 function install_begin_request(&$install_state) {
danielebarchiesi@0 211 // Add any installation parameters passed in via the URL.
danielebarchiesi@0 212 $install_state['parameters'] += $_GET;
danielebarchiesi@0 213
danielebarchiesi@0 214 // Validate certain core settings that are used throughout the installation.
danielebarchiesi@0 215 if (!empty($install_state['parameters']['profile'])) {
danielebarchiesi@0 216 $install_state['parameters']['profile'] = preg_replace('/[^a-zA-Z_0-9]/', '', $install_state['parameters']['profile']);
danielebarchiesi@0 217 }
danielebarchiesi@0 218 if (!empty($install_state['parameters']['locale'])) {
danielebarchiesi@0 219 $install_state['parameters']['locale'] = preg_replace('/[^a-zA-Z_0-9\-]/', '', $install_state['parameters']['locale']);
danielebarchiesi@0 220 }
danielebarchiesi@0 221
danielebarchiesi@0 222 // Allow command line scripts to override server variables used by Drupal.
danielebarchiesi@0 223 require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
danielebarchiesi@0 224 if (!$install_state['interactive']) {
danielebarchiesi@0 225 drupal_override_server_variables($install_state['server']);
danielebarchiesi@0 226 }
danielebarchiesi@0 227
danielebarchiesi@0 228 // The user agent header is used to pass a database prefix in the request when
danielebarchiesi@0 229 // running tests. However, for security reasons, it is imperative that no
danielebarchiesi@0 230 // installation be permitted using such a prefix.
danielebarchiesi@0 231 if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) {
danielebarchiesi@0 232 header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
danielebarchiesi@0 233 exit;
danielebarchiesi@0 234 }
danielebarchiesi@0 235
danielebarchiesi@0 236 drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
danielebarchiesi@0 237
danielebarchiesi@0 238 // This must go after drupal_bootstrap(), which unsets globals!
danielebarchiesi@0 239 global $conf;
danielebarchiesi@0 240
danielebarchiesi@0 241 require_once DRUPAL_ROOT . '/modules/system/system.install';
danielebarchiesi@0 242 require_once DRUPAL_ROOT . '/includes/common.inc';
danielebarchiesi@0 243 require_once DRUPAL_ROOT . '/includes/file.inc';
danielebarchiesi@0 244 require_once DRUPAL_ROOT . '/includes/install.inc';
danielebarchiesi@0 245 require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
danielebarchiesi@0 246
danielebarchiesi@0 247 // Load module basics (needed for hook invokes).
danielebarchiesi@0 248 include_once DRUPAL_ROOT . '/includes/module.inc';
danielebarchiesi@0 249 include_once DRUPAL_ROOT . '/includes/session.inc';
danielebarchiesi@0 250
danielebarchiesi@0 251 // Set up $language, so t() caller functions will still work.
danielebarchiesi@0 252 drupal_language_initialize();
danielebarchiesi@0 253
danielebarchiesi@0 254 include_once DRUPAL_ROOT . '/includes/entity.inc';
danielebarchiesi@0 255 require_once DRUPAL_ROOT . '/includes/ajax.inc';
danielebarchiesi@0 256 $module_list['system']['filename'] = 'modules/system/system.module';
danielebarchiesi@0 257 $module_list['user']['filename'] = 'modules/user/user.module';
danielebarchiesi@0 258 module_list(TRUE, FALSE, FALSE, $module_list);
danielebarchiesi@0 259 drupal_load('module', 'system');
danielebarchiesi@0 260 drupal_load('module', 'user');
danielebarchiesi@0 261
danielebarchiesi@0 262 // Load the cache infrastructure using a "fake" cache implementation that
danielebarchiesi@0 263 // does not attempt to write to the database. We need this during the initial
danielebarchiesi@0 264 // part of the installer because the database is not available yet. We
danielebarchiesi@0 265 // continue to use it even when the database does become available, in order
danielebarchiesi@0 266 // to preserve consistency between interactive and command-line installations
danielebarchiesi@0 267 // (the latter complete in one page request and therefore are forced to
danielebarchiesi@0 268 // continue using the cache implementation they started with) and also
danielebarchiesi@0 269 // because any data put in the cache during the installer is inherently
danielebarchiesi@0 270 // suspect, due to the fact that Drupal is not fully set up yet.
danielebarchiesi@0 271 require_once DRUPAL_ROOT . '/includes/cache.inc';
danielebarchiesi@0 272 require_once DRUPAL_ROOT . '/includes/cache-install.inc';
danielebarchiesi@0 273 $conf['cache_default_class'] = 'DrupalFakeCache';
danielebarchiesi@0 274
danielebarchiesi@0 275 // Prepare for themed output. We need to run this at the beginning of the
danielebarchiesi@0 276 // page request to avoid a different theme accidentally getting set. (We also
danielebarchiesi@0 277 // need to run it even in the case of command-line installations, to prevent
danielebarchiesi@0 278 // any code in the installer that happens to initialize the theme system from
danielebarchiesi@0 279 // accessing the database before it is set up yet.)
danielebarchiesi@0 280 drupal_maintenance_theme();
danielebarchiesi@0 281
danielebarchiesi@0 282 // Check existing settings.php.
danielebarchiesi@0 283 $install_state['settings_verified'] = install_verify_settings();
danielebarchiesi@0 284
danielebarchiesi@0 285 if ($install_state['settings_verified']) {
danielebarchiesi@0 286 // Initialize the database system. Note that the connection
danielebarchiesi@0 287 // won't be initialized until it is actually requested.
danielebarchiesi@0 288 require_once DRUPAL_ROOT . '/includes/database/database.inc';
danielebarchiesi@0 289
danielebarchiesi@0 290 // Verify the last completed task in the database, if there is one.
danielebarchiesi@0 291 $task = install_verify_completed_task();
danielebarchiesi@0 292 }
danielebarchiesi@0 293 else {
danielebarchiesi@0 294 $task = NULL;
danielebarchiesi@0 295
danielebarchiesi@0 296 // Do not install over a configured settings.php. Check the 'db_url'
danielebarchiesi@0 297 // variable in addition to 'databases', since previous versions of Drupal
danielebarchiesi@0 298 // used that (and we do not want to allow installations on an existing site
danielebarchiesi@0 299 // whose settings file has not yet been updated).
danielebarchiesi@0 300 if (!empty($GLOBALS['databases']) || !empty($GLOBALS['db_url'])) {
danielebarchiesi@0 301 throw new Exception(install_already_done_error());
danielebarchiesi@0 302 }
danielebarchiesi@0 303 }
danielebarchiesi@0 304
danielebarchiesi@0 305 // Modify the installation state as appropriate.
danielebarchiesi@0 306 $install_state['completed_task'] = $task;
danielebarchiesi@0 307 $install_state['database_tables_exist'] = !empty($task);
danielebarchiesi@0 308 }
danielebarchiesi@0 309
danielebarchiesi@0 310 /**
danielebarchiesi@0 311 * Runs all tasks for the current installation request.
danielebarchiesi@0 312 *
danielebarchiesi@0 313 * In the case of an interactive installation, all tasks will be attempted
danielebarchiesi@0 314 * until one is reached that has output which needs to be displayed to the
danielebarchiesi@0 315 * user, or until a page redirect is required. Otherwise, tasks will be
danielebarchiesi@0 316 * attempted until the installation is finished.
danielebarchiesi@0 317 *
danielebarchiesi@0 318 * @param $install_state
danielebarchiesi@0 319 * An array of information about the current installation state. This is
danielebarchiesi@0 320 * passed along to each task, so it can be modified if necessary.
danielebarchiesi@0 321 *
danielebarchiesi@0 322 * @return
danielebarchiesi@0 323 * HTML output from the last completed task.
danielebarchiesi@0 324 */
danielebarchiesi@0 325 function install_run_tasks(&$install_state) {
danielebarchiesi@0 326 do {
danielebarchiesi@0 327 // Obtain a list of tasks to perform. The list of tasks itself can be
danielebarchiesi@0 328 // dynamic (e.g., some might be defined by the installation profile,
danielebarchiesi@0 329 // which is not necessarily known until the earlier tasks have run),
danielebarchiesi@0 330 // so we regenerate the remaining tasks based on the installation state,
danielebarchiesi@0 331 // each time through the loop.
danielebarchiesi@0 332 $tasks_to_perform = install_tasks_to_perform($install_state);
danielebarchiesi@0 333 // Run the first task on the list.
danielebarchiesi@0 334 reset($tasks_to_perform);
danielebarchiesi@0 335 $task_name = key($tasks_to_perform);
danielebarchiesi@0 336 $task = array_shift($tasks_to_perform);
danielebarchiesi@0 337 $install_state['active_task'] = $task_name;
danielebarchiesi@0 338 $original_parameters = $install_state['parameters'];
danielebarchiesi@0 339 $output = install_run_task($task, $install_state);
danielebarchiesi@0 340 $install_state['parameters_changed'] = ($install_state['parameters'] != $original_parameters);
danielebarchiesi@0 341 // Store this task as having been performed during the current request,
danielebarchiesi@0 342 // and save it to the database as completed, if we need to and if the
danielebarchiesi@0 343 // database is in a state that allows us to do so. Also mark the
danielebarchiesi@0 344 // installation as 'done' when we have run out of tasks.
danielebarchiesi@0 345 if (!$install_state['task_not_complete']) {
danielebarchiesi@0 346 $install_state['tasks_performed'][] = $task_name;
danielebarchiesi@0 347 $install_state['installation_finished'] = empty($tasks_to_perform);
danielebarchiesi@0 348 if ($install_state['database_tables_exist'] && ($task['run'] == INSTALL_TASK_RUN_IF_NOT_COMPLETED || $install_state['installation_finished'])) {
danielebarchiesi@0 349 variable_set('install_task', $install_state['installation_finished'] ? 'done' : $task_name);
danielebarchiesi@0 350 }
danielebarchiesi@0 351 }
danielebarchiesi@0 352 // Stop when there are no tasks left. In the case of an interactive
danielebarchiesi@0 353 // installation, also stop if we have some output to send to the browser,
danielebarchiesi@0 354 // the URL parameters have changed, or an end to the page request was
danielebarchiesi@0 355 // specifically called for.
danielebarchiesi@0 356 $finished = empty($tasks_to_perform) || ($install_state['interactive'] && (isset($output) || $install_state['parameters_changed'] || $install_state['stop_page_request']));
danielebarchiesi@0 357 } while (!$finished);
danielebarchiesi@0 358 return $output;
danielebarchiesi@0 359 }
danielebarchiesi@0 360
danielebarchiesi@0 361 /**
danielebarchiesi@0 362 * Runs an individual installation task.
danielebarchiesi@0 363 *
danielebarchiesi@0 364 * @param $task
danielebarchiesi@0 365 * An array of information about the task to be run.
danielebarchiesi@0 366 * @param $install_state
danielebarchiesi@0 367 * An array of information about the current installation state. This is
danielebarchiesi@0 368 * passed in by reference so that it can be modified by the task.
danielebarchiesi@0 369 *
danielebarchiesi@0 370 * @return
danielebarchiesi@0 371 * The output of the task function, if there is any.
danielebarchiesi@0 372 */
danielebarchiesi@0 373 function install_run_task($task, &$install_state) {
danielebarchiesi@0 374 $function = $task['function'];
danielebarchiesi@0 375
danielebarchiesi@0 376 if ($task['type'] == 'form') {
danielebarchiesi@0 377 require_once DRUPAL_ROOT . '/includes/form.inc';
danielebarchiesi@0 378 if ($install_state['interactive']) {
danielebarchiesi@0 379 // For interactive forms, build the form and ensure that it will not
danielebarchiesi@0 380 // redirect, since the installer handles its own redirection only after
danielebarchiesi@0 381 // marking the form submission task complete.
danielebarchiesi@0 382 $form_state = array(
danielebarchiesi@0 383 // We need to pass $install_state by reference in order for forms to
danielebarchiesi@0 384 // modify it, since the form API will use it in call_user_func_array(),
danielebarchiesi@0 385 // which requires that referenced variables be passed explicitly.
danielebarchiesi@0 386 'build_info' => array('args' => array(&$install_state)),
danielebarchiesi@0 387 'no_redirect' => TRUE,
danielebarchiesi@0 388 );
danielebarchiesi@0 389 $form = drupal_build_form($function, $form_state);
danielebarchiesi@0 390 // If a successful form submission did not occur, the form needs to be
danielebarchiesi@0 391 // rendered, which means the task is not complete yet.
danielebarchiesi@0 392 if (empty($form_state['executed'])) {
danielebarchiesi@0 393 $install_state['task_not_complete'] = TRUE;
danielebarchiesi@0 394 return drupal_render($form);
danielebarchiesi@0 395 }
danielebarchiesi@0 396 // Otherwise, return nothing so the next task will run in the same
danielebarchiesi@0 397 // request.
danielebarchiesi@0 398 return;
danielebarchiesi@0 399 }
danielebarchiesi@0 400 else {
danielebarchiesi@0 401 // For non-interactive forms, submit the form programmatically with the
danielebarchiesi@0 402 // values taken from the installation state. Throw an exception if any
danielebarchiesi@0 403 // errors were encountered.
danielebarchiesi@0 404 $form_state = array(
danielebarchiesi@0 405 'values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array(),
danielebarchiesi@0 406 // We need to pass $install_state by reference in order for forms to
danielebarchiesi@0 407 // modify it, since the form API will use it in call_user_func_array(),
danielebarchiesi@0 408 // which requires that referenced variables be passed explicitly.
danielebarchiesi@0 409 'build_info' => array('args' => array(&$install_state)),
danielebarchiesi@0 410 );
danielebarchiesi@0 411 drupal_form_submit($function, $form_state);
danielebarchiesi@0 412 $errors = form_get_errors();
danielebarchiesi@0 413 if (!empty($errors)) {
danielebarchiesi@0 414 throw new Exception(implode("\n", $errors));
danielebarchiesi@0 415 }
danielebarchiesi@0 416 }
danielebarchiesi@0 417 }
danielebarchiesi@0 418
danielebarchiesi@0 419 elseif ($task['type'] == 'batch') {
danielebarchiesi@0 420 // Start a new batch based on the task function, if one is not running
danielebarchiesi@0 421 // already.
danielebarchiesi@0 422 $current_batch = variable_get('install_current_batch');
danielebarchiesi@0 423 if (!$install_state['interactive'] || !$current_batch) {
danielebarchiesi@0 424 $batch = $function($install_state);
danielebarchiesi@0 425 if (empty($batch)) {
danielebarchiesi@0 426 // If the task did some processing and decided no batch was necessary,
danielebarchiesi@0 427 // there is nothing more to do here.
danielebarchiesi@0 428 return;
danielebarchiesi@0 429 }
danielebarchiesi@0 430 batch_set($batch);
danielebarchiesi@0 431 // For interactive batches, we need to store the fact that this batch
danielebarchiesi@0 432 // task is currently running. Otherwise, we need to make sure the batch
danielebarchiesi@0 433 // will complete in one page request.
danielebarchiesi@0 434 if ($install_state['interactive']) {
danielebarchiesi@0 435 variable_set('install_current_batch', $function);
danielebarchiesi@0 436 }
danielebarchiesi@0 437 else {
danielebarchiesi@0 438 $batch =& batch_get();
danielebarchiesi@0 439 $batch['progressive'] = FALSE;
danielebarchiesi@0 440 }
danielebarchiesi@0 441 // Process the batch. For progressive batches, this will redirect.
danielebarchiesi@0 442 // Otherwise, the batch will complete.
danielebarchiesi@0 443 batch_process(install_redirect_url($install_state), install_full_redirect_url($install_state));
danielebarchiesi@0 444 }
danielebarchiesi@0 445 // If we are in the middle of processing this batch, keep sending back
danielebarchiesi@0 446 // any output from the batch process, until the task is complete.
danielebarchiesi@0 447 elseif ($current_batch == $function) {
danielebarchiesi@0 448 include_once DRUPAL_ROOT . '/includes/batch.inc';
danielebarchiesi@0 449 $output = _batch_page();
danielebarchiesi@0 450 // The task is complete when we try to access the batch page and receive
danielebarchiesi@0 451 // FALSE in return, since this means we are at a URL where we are no
danielebarchiesi@0 452 // longer requesting a batch ID.
danielebarchiesi@0 453 if ($output === FALSE) {
danielebarchiesi@0 454 // Return nothing so the next task will run in the same request.
danielebarchiesi@0 455 variable_del('install_current_batch');
danielebarchiesi@0 456 return;
danielebarchiesi@0 457 }
danielebarchiesi@0 458 else {
danielebarchiesi@0 459 // We need to force the page request to end if the task is not
danielebarchiesi@0 460 // complete, since the batch API sometimes prints JSON output
danielebarchiesi@0 461 // rather than returning a themed page.
danielebarchiesi@0 462 $install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;
danielebarchiesi@0 463 return $output;
danielebarchiesi@0 464 }
danielebarchiesi@0 465 }
danielebarchiesi@0 466 }
danielebarchiesi@0 467
danielebarchiesi@0 468 else {
danielebarchiesi@0 469 // For normal tasks, just return the function result, whatever it is.
danielebarchiesi@0 470 return $function($install_state);
danielebarchiesi@0 471 }
danielebarchiesi@0 472 }
danielebarchiesi@0 473
danielebarchiesi@0 474 /**
danielebarchiesi@0 475 * Returns a list of tasks to perform during the current installation request.
danielebarchiesi@0 476 *
danielebarchiesi@0 477 * Note that the list of tasks can change based on the installation state as
danielebarchiesi@0 478 * the page request evolves (for example, if an installation profile hasn't
danielebarchiesi@0 479 * been selected yet, we don't yet know which profile tasks need to be run).
danielebarchiesi@0 480 *
danielebarchiesi@0 481 * @param $install_state
danielebarchiesi@0 482 * An array of information about the current installation state.
danielebarchiesi@0 483 *
danielebarchiesi@0 484 * @return
danielebarchiesi@0 485 * A list of tasks to be performed, with associated metadata.
danielebarchiesi@0 486 */
danielebarchiesi@0 487 function install_tasks_to_perform($install_state) {
danielebarchiesi@0 488 // Start with a list of all currently available tasks.
danielebarchiesi@0 489 $tasks = install_tasks($install_state);
danielebarchiesi@0 490 foreach ($tasks as $name => $task) {
danielebarchiesi@0 491 // Remove any tasks that were already performed or that never should run.
danielebarchiesi@0 492 // Also, if we started this page request with an indication of the last
danielebarchiesi@0 493 // task that was completed, skip that task and all those that come before
danielebarchiesi@0 494 // it, unless they are marked as always needing to run.
danielebarchiesi@0 495 if ($task['run'] == INSTALL_TASK_SKIP || in_array($name, $install_state['tasks_performed']) || (!empty($install_state['completed_task']) && empty($completed_task_found) && $task['run'] != INSTALL_TASK_RUN_IF_REACHED)) {
danielebarchiesi@0 496 unset($tasks[$name]);
danielebarchiesi@0 497 }
danielebarchiesi@0 498 if (!empty($install_state['completed_task']) && $name == $install_state['completed_task']) {
danielebarchiesi@0 499 $completed_task_found = TRUE;
danielebarchiesi@0 500 }
danielebarchiesi@0 501 }
danielebarchiesi@0 502 return $tasks;
danielebarchiesi@0 503 }
danielebarchiesi@0 504
danielebarchiesi@0 505 /**
danielebarchiesi@0 506 * Returns a list of all tasks the installer currently knows about.
danielebarchiesi@0 507 *
danielebarchiesi@0 508 * This function will return tasks regardless of whether or not they are
danielebarchiesi@0 509 * intended to run on the current page request. However, the list can change
danielebarchiesi@0 510 * based on the installation state (for example, if an installation profile
danielebarchiesi@0 511 * hasn't been selected yet, we don't yet know which profile tasks will be
danielebarchiesi@0 512 * available).
danielebarchiesi@0 513 *
danielebarchiesi@0 514 * @param $install_state
danielebarchiesi@0 515 * An array of information about the current installation state.
danielebarchiesi@0 516 *
danielebarchiesi@0 517 * @return
danielebarchiesi@0 518 * A list of tasks, with associated metadata.
danielebarchiesi@0 519 */
danielebarchiesi@0 520 function install_tasks($install_state) {
danielebarchiesi@0 521 // Determine whether translation import tasks will need to be performed.
danielebarchiesi@0 522 $needs_translations = count($install_state['locales']) > 1 && !empty($install_state['parameters']['locale']) && $install_state['parameters']['locale'] != 'en';
danielebarchiesi@0 523
danielebarchiesi@0 524 // Start with the core installation tasks that run before handing control
danielebarchiesi@0 525 // to the installation profile.
danielebarchiesi@0 526 $tasks = array(
danielebarchiesi@0 527 'install_select_profile' => array(
danielebarchiesi@0 528 'display_name' => st('Choose profile'),
danielebarchiesi@0 529 'display' => count($install_state['profiles']) != 1,
danielebarchiesi@0 530 'run' => INSTALL_TASK_RUN_IF_REACHED,
danielebarchiesi@0 531 ),
danielebarchiesi@0 532 'install_select_locale' => array(
danielebarchiesi@0 533 'display_name' => st('Choose language'),
danielebarchiesi@0 534 'run' => INSTALL_TASK_RUN_IF_REACHED,
danielebarchiesi@0 535 ),
danielebarchiesi@0 536 'install_load_profile' => array(
danielebarchiesi@0 537 'run' => INSTALL_TASK_RUN_IF_REACHED,
danielebarchiesi@0 538 ),
danielebarchiesi@0 539 'install_verify_requirements' => array(
danielebarchiesi@0 540 'display_name' => st('Verify requirements'),
danielebarchiesi@0 541 ),
danielebarchiesi@0 542 'install_settings_form' => array(
danielebarchiesi@0 543 'display_name' => st('Set up database'),
danielebarchiesi@0 544 'type' => 'form',
danielebarchiesi@0 545 'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
danielebarchiesi@0 546 ),
danielebarchiesi@0 547 'install_system_module' => array(
danielebarchiesi@0 548 ),
danielebarchiesi@0 549 'install_bootstrap_full' => array(
danielebarchiesi@0 550 'run' => INSTALL_TASK_RUN_IF_REACHED,
danielebarchiesi@0 551 ),
danielebarchiesi@0 552 'install_profile_modules' => array(
danielebarchiesi@0 553 'display_name' => count($install_state['profiles']) == 1 ? st('Install site') : st('Install profile'),
danielebarchiesi@0 554 'type' => 'batch',
danielebarchiesi@0 555 ),
danielebarchiesi@0 556 'install_import_locales' => array(
danielebarchiesi@0 557 'display_name' => st('Set up translations'),
danielebarchiesi@0 558 'display' => $needs_translations,
danielebarchiesi@0 559 'type' => 'batch',
danielebarchiesi@0 560 'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
danielebarchiesi@0 561 ),
danielebarchiesi@0 562 'install_configure_form' => array(
danielebarchiesi@0 563 'display_name' => st('Configure site'),
danielebarchiesi@0 564 'type' => 'form',
danielebarchiesi@0 565 ),
danielebarchiesi@0 566 );
danielebarchiesi@0 567
danielebarchiesi@0 568 // Now add any tasks defined by the installation profile.
danielebarchiesi@0 569 if (!empty($install_state['parameters']['profile'])) {
danielebarchiesi@0 570 // Load the profile install file, because it is not always loaded when
danielebarchiesi@0 571 // hook_install_tasks() is invoked (e.g. batch processing).
danielebarchiesi@0 572 $profile_install_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.install';
danielebarchiesi@0 573 if (file_exists($profile_install_file)) {
danielebarchiesi@0 574 include_once $profile_install_file;
danielebarchiesi@0 575 }
danielebarchiesi@0 576 $function = $install_state['parameters']['profile'] . '_install_tasks';
danielebarchiesi@0 577 if (function_exists($function)) {
danielebarchiesi@0 578 $result = $function($install_state);
danielebarchiesi@0 579 if (is_array($result)) {
danielebarchiesi@0 580 $tasks += $result;
danielebarchiesi@0 581 }
danielebarchiesi@0 582 }
danielebarchiesi@0 583 }
danielebarchiesi@0 584
danielebarchiesi@0 585 // Finish by adding the remaining core tasks.
danielebarchiesi@0 586 $tasks += array(
danielebarchiesi@0 587 'install_import_locales_remaining' => array(
danielebarchiesi@0 588 'display_name' => st('Finish translations'),
danielebarchiesi@0 589 'display' => $needs_translations,
danielebarchiesi@0 590 'type' => 'batch',
danielebarchiesi@0 591 'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
danielebarchiesi@0 592 ),
danielebarchiesi@0 593 'install_finished' => array(
danielebarchiesi@0 594 'display_name' => st('Finished'),
danielebarchiesi@0 595 ),
danielebarchiesi@0 596 );
danielebarchiesi@0 597
danielebarchiesi@0 598 // Allow the installation profile to modify the full list of tasks.
danielebarchiesi@0 599 if (!empty($install_state['parameters']['profile'])) {
danielebarchiesi@0 600 $profile_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.profile';
danielebarchiesi@0 601 if (file_exists($profile_file)) {
danielebarchiesi@0 602 include_once $profile_file;
danielebarchiesi@0 603 $function = $install_state['parameters']['profile'] . '_install_tasks_alter';
danielebarchiesi@0 604 if (function_exists($function)) {
danielebarchiesi@0 605 $function($tasks, $install_state);
danielebarchiesi@0 606 }
danielebarchiesi@0 607 }
danielebarchiesi@0 608 }
danielebarchiesi@0 609
danielebarchiesi@0 610 // Fill in default parameters for each task before returning the list.
danielebarchiesi@0 611 foreach ($tasks as $task_name => &$task) {
danielebarchiesi@0 612 $task += array(
danielebarchiesi@0 613 'display_name' => NULL,
danielebarchiesi@0 614 'display' => !empty($task['display_name']),
danielebarchiesi@0 615 'type' => 'normal',
danielebarchiesi@0 616 'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
danielebarchiesi@0 617 'function' => $task_name,
danielebarchiesi@0 618 );
danielebarchiesi@0 619 }
danielebarchiesi@0 620 return $tasks;
danielebarchiesi@0 621 }
danielebarchiesi@0 622
danielebarchiesi@0 623 /**
danielebarchiesi@0 624 * Returns a list of tasks that should be displayed to the end user.
danielebarchiesi@0 625 *
danielebarchiesi@0 626 * The output of this function is a list suitable for sending to
danielebarchiesi@0 627 * theme_task_list().
danielebarchiesi@0 628 *
danielebarchiesi@0 629 * @param $install_state
danielebarchiesi@0 630 * An array of information about the current installation state.
danielebarchiesi@0 631 *
danielebarchiesi@0 632 * @return
danielebarchiesi@0 633 * A list of tasks, with keys equal to the machine-readable task name and
danielebarchiesi@0 634 * values equal to the name that should be displayed.
danielebarchiesi@0 635 *
danielebarchiesi@0 636 * @see theme_task_list()
danielebarchiesi@0 637 */
danielebarchiesi@0 638 function install_tasks_to_display($install_state) {
danielebarchiesi@0 639 $displayed_tasks = array();
danielebarchiesi@0 640 foreach (install_tasks($install_state) as $name => $task) {
danielebarchiesi@0 641 if ($task['display']) {
danielebarchiesi@0 642 $displayed_tasks[$name] = $task['display_name'];
danielebarchiesi@0 643 }
danielebarchiesi@0 644 }
danielebarchiesi@0 645 return $displayed_tasks;
danielebarchiesi@0 646 }
danielebarchiesi@0 647
danielebarchiesi@0 648 /**
danielebarchiesi@0 649 * Returns the URL that should be redirected to during an installation request.
danielebarchiesi@0 650 *
danielebarchiesi@0 651 * The output of this function is suitable for sending to install_goto().
danielebarchiesi@0 652 *
danielebarchiesi@0 653 * @param $install_state
danielebarchiesi@0 654 * An array of information about the current installation state.
danielebarchiesi@0 655 *
danielebarchiesi@0 656 * @return
danielebarchiesi@0 657 * The URL to redirect to.
danielebarchiesi@0 658 *
danielebarchiesi@0 659 * @see install_full_redirect_url()
danielebarchiesi@0 660 */
danielebarchiesi@0 661 function install_redirect_url($install_state) {
danielebarchiesi@0 662 return 'install.php?' . drupal_http_build_query($install_state['parameters']);
danielebarchiesi@0 663 }
danielebarchiesi@0 664
danielebarchiesi@0 665 /**
danielebarchiesi@0 666 * Returns the complete URL redirected to during an installation request.
danielebarchiesi@0 667 *
danielebarchiesi@0 668 * @param $install_state
danielebarchiesi@0 669 * An array of information about the current installation state.
danielebarchiesi@0 670 *
danielebarchiesi@0 671 * @return
danielebarchiesi@0 672 * The complete URL to redirect to.
danielebarchiesi@0 673 *
danielebarchiesi@0 674 * @see install_redirect_url()
danielebarchiesi@0 675 */
danielebarchiesi@0 676 function install_full_redirect_url($install_state) {
danielebarchiesi@0 677 global $base_url;
danielebarchiesi@0 678 return $base_url . '/' . install_redirect_url($install_state);
danielebarchiesi@0 679 }
danielebarchiesi@0 680
danielebarchiesi@0 681 /**
danielebarchiesi@0 682 * Displays themed installer output and ends the page request.
danielebarchiesi@0 683 *
danielebarchiesi@0 684 * Installation tasks should use drupal_set_title() to set the desired page
danielebarchiesi@0 685 * title, but otherwise this function takes care of theming the overall page
danielebarchiesi@0 686 * output during every step of the installation.
danielebarchiesi@0 687 *
danielebarchiesi@0 688 * @param $output
danielebarchiesi@0 689 * The content to display on the main part of the page.
danielebarchiesi@0 690 * @param $install_state
danielebarchiesi@0 691 * An array of information about the current installation state.
danielebarchiesi@0 692 */
danielebarchiesi@0 693 function install_display_output($output, $install_state) {
danielebarchiesi@0 694 drupal_page_header();
danielebarchiesi@0 695 // Only show the task list if there is an active task; otherwise, the page
danielebarchiesi@0 696 // request has ended before tasks have even been started, so there is nothing
danielebarchiesi@0 697 // meaningful to show.
danielebarchiesi@0 698 if (isset($install_state['active_task'])) {
danielebarchiesi@0 699 // Let the theming function know when every step of the installation has
danielebarchiesi@0 700 // been completed.
danielebarchiesi@0 701 $active_task = $install_state['installation_finished'] ? NULL : $install_state['active_task'];
danielebarchiesi@0 702 drupal_add_region_content('sidebar_first', theme('task_list', array('items' => install_tasks_to_display($install_state), 'active' => $active_task)));
danielebarchiesi@0 703 }
danielebarchiesi@0 704 print theme('install_page', array('content' => $output));
danielebarchiesi@0 705 exit;
danielebarchiesi@0 706 }
danielebarchiesi@0 707
danielebarchiesi@0 708 /**
danielebarchiesi@0 709 * Verifies the requirements for installing Drupal.
danielebarchiesi@0 710 *
danielebarchiesi@0 711 * @param $install_state
danielebarchiesi@0 712 * An array of information about the current installation state.
danielebarchiesi@0 713 *
danielebarchiesi@0 714 * @return
danielebarchiesi@0 715 * A themed status report, or an exception if there are requirement errors.
danielebarchiesi@0 716 * If there are only requirement warnings, a themed status report is shown
danielebarchiesi@0 717 * initially, but the user is allowed to bypass it by providing 'continue=1'
danielebarchiesi@0 718 * in the URL. Otherwise, no output is returned, so that the next task can be
danielebarchiesi@0 719 * run in the same page request.
danielebarchiesi@0 720 */
danielebarchiesi@0 721 function install_verify_requirements(&$install_state) {
danielebarchiesi@0 722 // Check the installation requirements for Drupal and this profile.
danielebarchiesi@0 723 $requirements = install_check_requirements($install_state);
danielebarchiesi@0 724
danielebarchiesi@0 725 // Verify existence of all required modules.
danielebarchiesi@0 726 $requirements += drupal_verify_profile($install_state);
danielebarchiesi@0 727
danielebarchiesi@0 728 // Check the severity of the requirements reported.
danielebarchiesi@0 729 $severity = drupal_requirements_severity($requirements);
danielebarchiesi@0 730
danielebarchiesi@0 731 // If there are errors, always display them. If there are only warnings, skip
danielebarchiesi@0 732 // them if the user has provided a URL parameter acknowledging the warnings
danielebarchiesi@0 733 // and indicating a desire to continue anyway. See drupal_requirements_url().
danielebarchiesi@0 734 if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && empty($install_state['parameters']['continue']))) {
danielebarchiesi@0 735 if ($install_state['interactive']) {
danielebarchiesi@0 736 drupal_set_title(st('Requirements problem'));
danielebarchiesi@0 737 $status_report = theme('status_report', array('requirements' => $requirements));
danielebarchiesi@0 738 $status_report .= st('Check the error messages and <a href="!url">proceed with the installation</a>.', array('!url' => check_url(drupal_requirements_url($severity))));
danielebarchiesi@0 739 return $status_report;
danielebarchiesi@0 740 }
danielebarchiesi@0 741 else {
danielebarchiesi@0 742 // Throw an exception showing any unmet requirements.
danielebarchiesi@0 743 $failures = array();
danielebarchiesi@0 744 foreach ($requirements as $requirement) {
danielebarchiesi@0 745 // Skip warnings altogether for non-interactive installations; these
danielebarchiesi@0 746 // proceed in a single request so there is no good opportunity (and no
danielebarchiesi@0 747 // good method) to warn the user anyway.
danielebarchiesi@0 748 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
danielebarchiesi@0 749 $failures[] = $requirement['title'] . ': ' . $requirement['value'] . "\n\n" . $requirement['description'];
danielebarchiesi@0 750 }
danielebarchiesi@0 751 }
danielebarchiesi@0 752 if (!empty($failures)) {
danielebarchiesi@0 753 throw new Exception(implode("\n\n", $failures));
danielebarchiesi@0 754 }
danielebarchiesi@0 755 }
danielebarchiesi@0 756 }
danielebarchiesi@0 757 }
danielebarchiesi@0 758
danielebarchiesi@0 759 /**
danielebarchiesi@0 760 * Installation task; install the Drupal system module.
danielebarchiesi@0 761 *
danielebarchiesi@0 762 * @param $install_state
danielebarchiesi@0 763 * An array of information about the current installation state.
danielebarchiesi@0 764 */
danielebarchiesi@0 765 function install_system_module(&$install_state) {
danielebarchiesi@0 766 // Install system.module.
danielebarchiesi@0 767 drupal_install_system();
danielebarchiesi@0 768
danielebarchiesi@0 769 // Enable the user module so that sessions can be recorded during the
danielebarchiesi@0 770 // upcoming bootstrap step.
danielebarchiesi@0 771 module_enable(array('user'), FALSE);
danielebarchiesi@0 772
danielebarchiesi@0 773 // Save the list of other modules to install for the upcoming tasks.
danielebarchiesi@0 774 // variable_set() can be used now that system.module is installed.
danielebarchiesi@0 775 $modules = $install_state['profile_info']['dependencies'];
danielebarchiesi@0 776
danielebarchiesi@0 777 // The installation profile is also a module, which needs to be installed
danielebarchiesi@0 778 // after all the dependencies have been installed.
danielebarchiesi@0 779 $modules[] = drupal_get_profile();
danielebarchiesi@0 780
danielebarchiesi@0 781 variable_set('install_profile_modules', array_diff($modules, array('system')));
danielebarchiesi@0 782 $install_state['database_tables_exist'] = TRUE;
danielebarchiesi@0 783 }
danielebarchiesi@0 784
danielebarchiesi@0 785 /**
danielebarchiesi@0 786 * Verifies and returns the last installation task that was completed.
danielebarchiesi@0 787 *
danielebarchiesi@0 788 * @return
danielebarchiesi@0 789 * The last completed task, if there is one. An exception is thrown if Drupal
danielebarchiesi@0 790 * is already installed.
danielebarchiesi@0 791 */
danielebarchiesi@0 792 function install_verify_completed_task() {
danielebarchiesi@0 793 try {
danielebarchiesi@0 794 if ($result = db_query("SELECT value FROM {variable} WHERE name = :name", array('name' => 'install_task'))) {
danielebarchiesi@0 795 $task = unserialize($result->fetchField());
danielebarchiesi@0 796 }
danielebarchiesi@0 797 }
danielebarchiesi@0 798 // Do not trigger an error if the database query fails, since the database
danielebarchiesi@0 799 // might not be set up yet.
danielebarchiesi@0 800 catch (Exception $e) {
danielebarchiesi@0 801 }
danielebarchiesi@0 802 if (isset($task)) {
danielebarchiesi@0 803 if ($task == 'done') {
danielebarchiesi@0 804 throw new Exception(install_already_done_error());
danielebarchiesi@0 805 }
danielebarchiesi@0 806 return $task;
danielebarchiesi@0 807 }
danielebarchiesi@0 808 }
danielebarchiesi@0 809
danielebarchiesi@0 810 /**
danielebarchiesi@0 811 * Verifies the existing settings in settings.php.
danielebarchiesi@0 812 */
danielebarchiesi@0 813 function install_verify_settings() {
danielebarchiesi@0 814 global $databases;
danielebarchiesi@0 815
danielebarchiesi@0 816 // Verify existing settings (if any).
danielebarchiesi@0 817 if (!empty($databases) && install_verify_pdo()) {
danielebarchiesi@0 818 $database = $databases['default']['default'];
danielebarchiesi@0 819 drupal_static_reset('conf_path');
danielebarchiesi@0 820 $settings_file = './' . conf_path(FALSE) . '/settings.php';
danielebarchiesi@0 821 $errors = install_database_errors($database, $settings_file);
danielebarchiesi@0 822 if (empty($errors)) {
danielebarchiesi@0 823 return TRUE;
danielebarchiesi@0 824 }
danielebarchiesi@0 825 }
danielebarchiesi@0 826 return FALSE;
danielebarchiesi@0 827 }
danielebarchiesi@0 828
danielebarchiesi@0 829 /**
danielebarchiesi@0 830 * Verifies the PDO library.
danielebarchiesi@0 831 */
danielebarchiesi@0 832 function install_verify_pdo() {
danielebarchiesi@0 833 // PDO was moved to PHP core in 5.2.0, but the old extension (targeting 5.0
danielebarchiesi@0 834 // and 5.1) is still available from PECL, and can still be built without
danielebarchiesi@0 835 // errors. To verify that the correct version is in use, we check the
danielebarchiesi@0 836 // PDO::ATTR_DEFAULT_FETCH_MODE constant, which is not available in the
danielebarchiesi@0 837 // PECL extension.
danielebarchiesi@0 838 return extension_loaded('pdo') && defined('PDO::ATTR_DEFAULT_FETCH_MODE');
danielebarchiesi@0 839 }
danielebarchiesi@0 840
danielebarchiesi@0 841 /**
danielebarchiesi@0 842 * Form constructor for a form to configure and rewrite settings.php.
danielebarchiesi@0 843 *
danielebarchiesi@0 844 * @param $install_state
danielebarchiesi@0 845 * An array of information about the current installation state.
danielebarchiesi@0 846 *
danielebarchiesi@0 847 * @see install_settings_form_validate()
danielebarchiesi@0 848 * @see install_settings_form_submit()
danielebarchiesi@0 849 * @ingroup forms
danielebarchiesi@0 850 */
danielebarchiesi@0 851 function install_settings_form($form, &$form_state, &$install_state) {
danielebarchiesi@0 852 global $databases;
danielebarchiesi@0 853 $profile = $install_state['parameters']['profile'];
danielebarchiesi@0 854 $install_locale = $install_state['parameters']['locale'];
danielebarchiesi@0 855
danielebarchiesi@0 856 drupal_static_reset('conf_path');
danielebarchiesi@0 857 $conf_path = './' . conf_path(FALSE);
danielebarchiesi@0 858 $settings_file = $conf_path . '/settings.php';
danielebarchiesi@0 859 $database = isset($databases['default']['default']) ? $databases['default']['default'] : array();
danielebarchiesi@0 860
danielebarchiesi@0 861 drupal_set_title(st('Database configuration'));
danielebarchiesi@0 862
danielebarchiesi@0 863 $drivers = drupal_get_database_types();
danielebarchiesi@0 864 $drivers_keys = array_keys($drivers);
danielebarchiesi@0 865
danielebarchiesi@0 866 $form['driver'] = array(
danielebarchiesi@0 867 '#type' => 'radios',
danielebarchiesi@0 868 '#title' => st('Database type'),
danielebarchiesi@0 869 '#required' => TRUE,
danielebarchiesi@0 870 '#default_value' => !empty($database['driver']) ? $database['driver'] : current($drivers_keys),
danielebarchiesi@0 871 '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_distribution_name())),
danielebarchiesi@0 872 );
danielebarchiesi@0 873 if (count($drivers) == 1) {
danielebarchiesi@0 874 $form['driver']['#disabled'] = TRUE;
danielebarchiesi@0 875 $form['driver']['#description'] .= ' ' . st('Your PHP configuration only supports a single database type, so it has been automatically selected.');
danielebarchiesi@0 876 }
danielebarchiesi@0 877
danielebarchiesi@0 878 // Add driver specific configuration options.
danielebarchiesi@0 879 foreach ($drivers as $key => $driver) {
danielebarchiesi@0 880 $form['driver']['#options'][$key] = $driver->name();
danielebarchiesi@0 881
danielebarchiesi@0 882 $form['settings'][$key] = $driver->getFormOptions($database);
danielebarchiesi@0 883 $form['settings'][$key]['#prefix'] = '<h2 class="js-hide">' . st('@driver_name settings', array('@driver_name' => $driver->name())) . '</h2>';
danielebarchiesi@0 884 $form['settings'][$key]['#type'] = 'container';
danielebarchiesi@0 885 $form['settings'][$key]['#tree'] = TRUE;
danielebarchiesi@0 886 $form['settings'][$key]['advanced_options']['#parents'] = array($key);
danielebarchiesi@0 887 $form['settings'][$key]['#states'] = array(
danielebarchiesi@0 888 'visible' => array(
danielebarchiesi@0 889 ':input[name=driver]' => array('value' => $key),
danielebarchiesi@0 890 )
danielebarchiesi@0 891 );
danielebarchiesi@0 892 }
danielebarchiesi@0 893
danielebarchiesi@0 894 $form['actions'] = array('#type' => 'actions');
danielebarchiesi@0 895 $form['actions']['save'] = array(
danielebarchiesi@0 896 '#type' => 'submit',
danielebarchiesi@0 897 '#value' => st('Save and continue'),
danielebarchiesi@0 898 '#limit_validation_errors' => array(
danielebarchiesi@0 899 array('driver'),
danielebarchiesi@0 900 array(isset($form_state['input']['driver']) ? $form_state['input']['driver'] : current($drivers_keys)),
danielebarchiesi@0 901 ),
danielebarchiesi@0 902 '#submit' => array('install_settings_form_submit'),
danielebarchiesi@0 903 );
danielebarchiesi@0 904
danielebarchiesi@0 905 $form['errors'] = array();
danielebarchiesi@0 906 $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);
danielebarchiesi@0 907
danielebarchiesi@0 908 return $form;
danielebarchiesi@0 909 }
danielebarchiesi@0 910
danielebarchiesi@0 911 /**
danielebarchiesi@0 912 * Form validation handler for install_settings_form().
danielebarchiesi@0 913 *
danielebarchiesi@0 914 * @see install_settings_form_submit()
danielebarchiesi@0 915 */
danielebarchiesi@0 916 function install_settings_form_validate($form, &$form_state) {
danielebarchiesi@0 917 $driver = $form_state['values']['driver'];
danielebarchiesi@0 918 $database = $form_state['values'][$driver];
danielebarchiesi@0 919 $database['driver'] = $driver;
danielebarchiesi@0 920
danielebarchiesi@0 921 // TODO: remove when PIFR will be updated to use 'db_prefix' instead of
danielebarchiesi@0 922 // 'prefix' in the database settings form.
danielebarchiesi@0 923 $database['prefix'] = $database['db_prefix'];
danielebarchiesi@0 924 unset($database['db_prefix']);
danielebarchiesi@0 925
danielebarchiesi@0 926 $form_state['storage']['database'] = $database;
danielebarchiesi@0 927 $errors = install_database_errors($database, $form_state['values']['settings_file']);
danielebarchiesi@0 928 foreach ($errors as $name => $message) {
danielebarchiesi@0 929 form_set_error($name, $message);
danielebarchiesi@0 930 }
danielebarchiesi@0 931 }
danielebarchiesi@0 932
danielebarchiesi@0 933 /**
danielebarchiesi@0 934 * Checks a database connection and returns any errors.
danielebarchiesi@0 935 */
danielebarchiesi@0 936 function install_database_errors($database, $settings_file) {
danielebarchiesi@0 937 global $databases;
danielebarchiesi@0 938 $errors = array();
danielebarchiesi@0 939
danielebarchiesi@0 940 // Check database type.
danielebarchiesi@0 941 $database_types = drupal_get_database_types();
danielebarchiesi@0 942 $driver = $database['driver'];
danielebarchiesi@0 943 if (!isset($database_types[$driver])) {
danielebarchiesi@0 944 $errors['driver'] = st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_distribution_name(), '%driver' => $driver));
danielebarchiesi@0 945 }
danielebarchiesi@0 946 else {
danielebarchiesi@0 947 // Run driver specific validation
danielebarchiesi@0 948 $errors += $database_types[$driver]->validateDatabaseSettings($database);
danielebarchiesi@0 949
danielebarchiesi@0 950 // Run tasks associated with the database type. Any errors are caught in the
danielebarchiesi@0 951 // calling function.
danielebarchiesi@0 952 $databases['default']['default'] = $database;
danielebarchiesi@0 953 // Just changing the global doesn't get the new information processed.
danielebarchiesi@0 954 // We tell tell the Database class to re-parse $databases.
danielebarchiesi@0 955 Database::parseConnectionInfo();
danielebarchiesi@0 956
danielebarchiesi@0 957 try {
danielebarchiesi@0 958 db_run_tasks($driver);
danielebarchiesi@0 959 }
danielebarchiesi@0 960 catch (DatabaseTaskException $e) {
danielebarchiesi@0 961 // These are generic errors, so we do not have any specific key of the
danielebarchiesi@0 962 // database connection array to attach them to; therefore, we just put
danielebarchiesi@0 963 // them in the error array with standard numeric keys.
danielebarchiesi@0 964 $errors[$driver . '][0'] = $e->getMessage();
danielebarchiesi@0 965 }
danielebarchiesi@0 966 }
danielebarchiesi@0 967 return $errors;
danielebarchiesi@0 968 }
danielebarchiesi@0 969
danielebarchiesi@0 970 /**
danielebarchiesi@0 971 * Form submission handler for install_settings_form().
danielebarchiesi@0 972 *
danielebarchiesi@0 973 * @see install_settings_form_validate()
danielebarchiesi@0 974 */
danielebarchiesi@0 975 function install_settings_form_submit($form, &$form_state) {
danielebarchiesi@0 976 global $install_state;
danielebarchiesi@0 977
danielebarchiesi@0 978 // Update global settings array and save.
danielebarchiesi@0 979 $settings['databases'] = array(
danielebarchiesi@0 980 'value' => array('default' => array('default' => $form_state['storage']['database'])),
danielebarchiesi@0 981 'required' => TRUE,
danielebarchiesi@0 982 );
danielebarchiesi@0 983 $settings['drupal_hash_salt'] = array(
danielebarchiesi@0 984 'value' => drupal_hash_base64(drupal_random_bytes(55)),
danielebarchiesi@0 985 'required' => TRUE,
danielebarchiesi@0 986 );
danielebarchiesi@0 987 drupal_rewrite_settings($settings);
danielebarchiesi@0 988 // Indicate that the settings file has been verified, and check the database
danielebarchiesi@0 989 // for the last completed task, now that we have a valid connection. This
danielebarchiesi@0 990 // last step is important since we want to trigger an error if the new
danielebarchiesi@0 991 // database already has Drupal installed.
danielebarchiesi@0 992 $install_state['settings_verified'] = TRUE;
danielebarchiesi@0 993 $install_state['completed_task'] = install_verify_completed_task();
danielebarchiesi@0 994 }
danielebarchiesi@0 995
danielebarchiesi@0 996 /**
danielebarchiesi@0 997 * Finds all .profile files.
danielebarchiesi@0 998 */
danielebarchiesi@0 999 function install_find_profiles() {
danielebarchiesi@0 1000 return file_scan_directory('./profiles', '/\.profile$/', array('key' => 'name'));
danielebarchiesi@0 1001 }
danielebarchiesi@0 1002
danielebarchiesi@0 1003 /**
danielebarchiesi@0 1004 * Selects which profile to install.
danielebarchiesi@0 1005 *
danielebarchiesi@0 1006 * @param $install_state
danielebarchiesi@0 1007 * An array of information about the current installation state. The chosen
danielebarchiesi@0 1008 * profile will be added here, if it was not already selected previously, as
danielebarchiesi@0 1009 * will a list of all available profiles.
danielebarchiesi@0 1010 *
danielebarchiesi@0 1011 * @return
danielebarchiesi@0 1012 * For interactive installations, a form allowing the profile to be selected,
danielebarchiesi@0 1013 * if the user has a choice that needs to be made. Otherwise, an exception is
danielebarchiesi@0 1014 * thrown if a profile cannot be chosen automatically.
danielebarchiesi@0 1015 */
danielebarchiesi@0 1016 function install_select_profile(&$install_state) {
danielebarchiesi@0 1017 $install_state['profiles'] += install_find_profiles();
danielebarchiesi@0 1018 if (empty($install_state['parameters']['profile'])) {
danielebarchiesi@0 1019 // Try to find a profile.
danielebarchiesi@0 1020 $profile = _install_select_profile($install_state['profiles']);
danielebarchiesi@0 1021 if (empty($profile)) {
danielebarchiesi@0 1022 // We still don't have a profile, so display a form for selecting one.
danielebarchiesi@0 1023 // Only do this in the case of interactive installations, since this is
danielebarchiesi@0 1024 // not a real form with submit handlers (the database isn't even set up
danielebarchiesi@0 1025 // yet), rather just a convenience method for setting parameters in the
danielebarchiesi@0 1026 // URL.
danielebarchiesi@0 1027 if ($install_state['interactive']) {
danielebarchiesi@0 1028 include_once DRUPAL_ROOT . '/includes/form.inc';
danielebarchiesi@0 1029 drupal_set_title(st('Select an installation profile'));
danielebarchiesi@0 1030 $form = drupal_get_form('install_select_profile_form', $install_state['profiles']);
danielebarchiesi@0 1031 return drupal_render($form);
danielebarchiesi@0 1032 }
danielebarchiesi@0 1033 else {
danielebarchiesi@0 1034 throw new Exception(install_no_profile_error());
danielebarchiesi@0 1035 }
danielebarchiesi@0 1036 }
danielebarchiesi@0 1037 else {
danielebarchiesi@0 1038 $install_state['parameters']['profile'] = $profile;
danielebarchiesi@0 1039 }
danielebarchiesi@0 1040 }
danielebarchiesi@0 1041 }
danielebarchiesi@0 1042
danielebarchiesi@0 1043 /**
danielebarchiesi@0 1044 * Selects an installation profile.
danielebarchiesi@0 1045 *
danielebarchiesi@0 1046 * A profile will be selected if:
danielebarchiesi@0 1047 * - Only one profile is available,
danielebarchiesi@0 1048 * - A profile was submitted through $_POST,
danielebarchiesi@0 1049 * - Exactly one of the profiles is marked as "exclusive".
danielebarchiesi@0 1050 * If multiple profiles are marked as "exclusive" then no profile will be
danielebarchiesi@0 1051 * selected.
danielebarchiesi@0 1052 *
danielebarchiesi@0 1053 * @param array $profiles
danielebarchiesi@0 1054 * An associative array of profiles with the machine-readable names as keys.
danielebarchiesi@0 1055 *
danielebarchiesi@0 1056 * @return
danielebarchiesi@0 1057 * The machine-readable name of the selected profile or NULL if no profile was
danielebarchiesi@0 1058 * selected.
danielebarchiesi@0 1059 */
danielebarchiesi@0 1060 function _install_select_profile($profiles) {
danielebarchiesi@0 1061 if (sizeof($profiles) == 0) {
danielebarchiesi@0 1062 throw new Exception(install_no_profile_error());
danielebarchiesi@0 1063 }
danielebarchiesi@0 1064 // Don't need to choose profile if only one available.
danielebarchiesi@0 1065 if (sizeof($profiles) == 1) {
danielebarchiesi@0 1066 $profile = array_pop($profiles);
danielebarchiesi@0 1067 // TODO: is this right?
danielebarchiesi@0 1068 require_once DRUPAL_ROOT . '/' . $profile->uri;
danielebarchiesi@0 1069 return $profile->name;
danielebarchiesi@0 1070 }
danielebarchiesi@0 1071 else {
danielebarchiesi@0 1072 foreach ($profiles as $profile) {
danielebarchiesi@0 1073 if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) {
danielebarchiesi@0 1074 return $profile->name;
danielebarchiesi@0 1075 }
danielebarchiesi@0 1076 }
danielebarchiesi@0 1077 }
danielebarchiesi@0 1078 // Check for a profile marked as "exclusive" and ensure that only one
danielebarchiesi@0 1079 // profile is marked as such.
danielebarchiesi@0 1080 $exclusive_profile = NULL;
danielebarchiesi@0 1081 foreach ($profiles as $profile) {
danielebarchiesi@0 1082 $profile_info = install_profile_info($profile->name);
danielebarchiesi@0 1083 if (!empty($profile_info['exclusive'])) {
danielebarchiesi@0 1084 if (empty($exclusive_profile)) {
danielebarchiesi@0 1085 $exclusive_profile = $profile->name;
danielebarchiesi@0 1086 }
danielebarchiesi@0 1087 else {
danielebarchiesi@0 1088 // We found a second "exclusive" profile. There's no way to choose
danielebarchiesi@0 1089 // between them, so we ignore the property.
danielebarchiesi@0 1090 return;
danielebarchiesi@0 1091 }
danielebarchiesi@0 1092 }
danielebarchiesi@0 1093 }
danielebarchiesi@0 1094 return $exclusive_profile;
danielebarchiesi@0 1095 }
danielebarchiesi@0 1096
danielebarchiesi@0 1097 /**
danielebarchiesi@0 1098 * Form constructor for the profile selection form.
danielebarchiesi@0 1099 *
danielebarchiesi@0 1100 * @param $form_state
danielebarchiesi@0 1101 * Array of metadata about state of form processing.
danielebarchiesi@0 1102 * @param $profile_files
danielebarchiesi@0 1103 * Array of .profile files, as returned from file_scan_directory().
danielebarchiesi@0 1104 *
danielebarchiesi@0 1105 * @ingroup forms
danielebarchiesi@0 1106 */
danielebarchiesi@0 1107 function install_select_profile_form($form, &$form_state, $profile_files) {
danielebarchiesi@0 1108 $profiles = array();
danielebarchiesi@0 1109 $names = array();
danielebarchiesi@0 1110
danielebarchiesi@0 1111 foreach ($profile_files as $profile) {
danielebarchiesi@0 1112 // TODO: is this right?
danielebarchiesi@0 1113 include_once DRUPAL_ROOT . '/' . $profile->uri;
danielebarchiesi@0 1114
danielebarchiesi@0 1115 $details = install_profile_info($profile->name);
danielebarchiesi@0 1116 // Don't show hidden profiles. This is used by to hide the testing profile,
danielebarchiesi@0 1117 // which only exists to speed up test runs.
danielebarchiesi@0 1118 if ($details['hidden'] === TRUE) {
danielebarchiesi@0 1119 continue;
danielebarchiesi@0 1120 }
danielebarchiesi@0 1121 $profiles[$profile->name] = $details;
danielebarchiesi@0 1122
danielebarchiesi@0 1123 // Determine the name of the profile; default to file name if defined name
danielebarchiesi@0 1124 // is unspecified.
danielebarchiesi@0 1125 $name = isset($details['name']) ? $details['name'] : $profile->name;
danielebarchiesi@0 1126 $names[$profile->name] = $name;
danielebarchiesi@0 1127 }
danielebarchiesi@0 1128
danielebarchiesi@0 1129 // Display radio buttons alphabetically by human-readable name, but always
danielebarchiesi@0 1130 // put the core profiles first (if they are present in the filesystem).
danielebarchiesi@0 1131 natcasesort($names);
danielebarchiesi@0 1132 if (isset($names['minimal'])) {
danielebarchiesi@0 1133 // If the expert ("Minimal") core profile is present, put it in front of
danielebarchiesi@0 1134 // any non-core profiles rather than including it with them alphabetically,
danielebarchiesi@0 1135 // since the other profiles might be intended to group together in a
danielebarchiesi@0 1136 // particular way.
danielebarchiesi@0 1137 $names = array('minimal' => $names['minimal']) + $names;
danielebarchiesi@0 1138 }
danielebarchiesi@0 1139 if (isset($names['standard'])) {
danielebarchiesi@0 1140 // If the default ("Standard") core profile is present, put it at the very
danielebarchiesi@0 1141 // top of the list. This profile will have its radio button pre-selected,
danielebarchiesi@0 1142 // so we want it to always appear at the top.
danielebarchiesi@0 1143 $names = array('standard' => $names['standard']) + $names;
danielebarchiesi@0 1144 }
danielebarchiesi@0 1145
danielebarchiesi@0 1146 foreach ($names as $profile => $name) {
danielebarchiesi@0 1147 $form['profile'][$name] = array(
danielebarchiesi@0 1148 '#type' => 'radio',
danielebarchiesi@0 1149 '#value' => 'standard',
danielebarchiesi@0 1150 '#return_value' => $profile,
danielebarchiesi@0 1151 '#title' => $name,
danielebarchiesi@0 1152 '#description' => isset($profiles[$profile]['description']) ? $profiles[$profile]['description'] : '',
danielebarchiesi@0 1153 '#parents' => array('profile'),
danielebarchiesi@0 1154 );
danielebarchiesi@0 1155 }
danielebarchiesi@0 1156 $form['actions'] = array('#type' => 'actions');
danielebarchiesi@0 1157 $form['actions']['submit'] = array(
danielebarchiesi@0 1158 '#type' => 'submit',
danielebarchiesi@0 1159 '#value' => st('Save and continue'),
danielebarchiesi@0 1160 );
danielebarchiesi@0 1161 return $form;
danielebarchiesi@0 1162 }
danielebarchiesi@0 1163
danielebarchiesi@0 1164 /**
danielebarchiesi@0 1165 * Find all .po files for the current profile.
danielebarchiesi@0 1166 */
danielebarchiesi@0 1167 function install_find_locales($profilename) {
danielebarchiesi@0 1168 $locales = file_scan_directory('./profiles/' . $profilename . '/translations', '/\.po$/', array('recurse' => FALSE));
danielebarchiesi@0 1169 array_unshift($locales, (object) array('name' => 'en'));
danielebarchiesi@0 1170 foreach ($locales as $key => $locale) {
danielebarchiesi@0 1171 // The locale (file name) might be drupal-7.2.cs.po instead of cs.po.
danielebarchiesi@0 1172 $locales[$key]->langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $locale->name);
danielebarchiesi@0 1173 // Language codes cannot exceed 12 characters to fit into the {languages}
danielebarchiesi@0 1174 // table.
danielebarchiesi@0 1175 if (strlen($locales[$key]->langcode) > 12) {
danielebarchiesi@0 1176 unset($locales[$key]);
danielebarchiesi@0 1177 }
danielebarchiesi@0 1178 }
danielebarchiesi@0 1179 return $locales;
danielebarchiesi@0 1180 }
danielebarchiesi@0 1181
danielebarchiesi@0 1182 /**
danielebarchiesi@0 1183 * Installation task; select which locale to use for the current profile.
danielebarchiesi@0 1184 *
danielebarchiesi@0 1185 * @param $install_state
danielebarchiesi@0 1186 * An array of information about the current installation state. The chosen
danielebarchiesi@0 1187 * locale will be added here, if it was not already selected previously, as
danielebarchiesi@0 1188 * will a list of all available locales.
danielebarchiesi@0 1189 *
danielebarchiesi@0 1190 * @return
danielebarchiesi@0 1191 * For interactive installations, a form or other page output allowing the
danielebarchiesi@0 1192 * locale to be selected or providing information about locale selection, if
danielebarchiesi@0 1193 * a locale has not been chosen. Otherwise, an exception is thrown if a
danielebarchiesi@0 1194 * locale cannot be chosen automatically.
danielebarchiesi@0 1195 */
danielebarchiesi@0 1196 function install_select_locale(&$install_state) {
danielebarchiesi@0 1197 // Find all available locales.
danielebarchiesi@0 1198 $profilename = $install_state['parameters']['profile'];
danielebarchiesi@0 1199 $locales = install_find_locales($profilename);
danielebarchiesi@0 1200 $install_state['locales'] += $locales;
danielebarchiesi@0 1201
danielebarchiesi@0 1202 if (!empty($_POST['locale'])) {
danielebarchiesi@0 1203 foreach ($locales as $locale) {
danielebarchiesi@0 1204 if ($_POST['locale'] == $locale->langcode) {
danielebarchiesi@0 1205 $install_state['parameters']['locale'] = $locale->langcode;
danielebarchiesi@0 1206 return;
danielebarchiesi@0 1207 }
danielebarchiesi@0 1208 }
danielebarchiesi@0 1209 }
danielebarchiesi@0 1210
danielebarchiesi@0 1211 if (empty($install_state['parameters']['locale'])) {
danielebarchiesi@0 1212 // If only the built-in (English) language is available, and we are
danielebarchiesi@0 1213 // performing an interactive installation, inform the user that the
danielebarchiesi@0 1214 // installer can be localized. Otherwise we assume the user knows what he
danielebarchiesi@0 1215 // is doing.
danielebarchiesi@0 1216 if (count($locales) == 1) {
danielebarchiesi@0 1217 if ($install_state['interactive']) {
danielebarchiesi@0 1218 drupal_set_title(st('Choose language'));
danielebarchiesi@0 1219 if (!empty($install_state['parameters']['localize'])) {
danielebarchiesi@0 1220 $output = '<p>Follow these steps to translate Drupal into your language:</p>';
danielebarchiesi@0 1221 $output .= '<ol>';
danielebarchiesi@0 1222 $output .= '<li>Download a translation from the <a href="http://localize.drupal.org/download" target="_blank">translation server</a>.</li>';
danielebarchiesi@0 1223 $output .= '<li>Place it into the following directory:
danielebarchiesi@0 1224 <pre>
danielebarchiesi@0 1225 /profiles/' . $profilename . '/translations/
danielebarchiesi@0 1226 </pre></li>';
danielebarchiesi@0 1227 $output .= '</ol>';
danielebarchiesi@0 1228 $output .= '<p>For more information on installing Drupal in different languages, visit the <a href="http://drupal.org/localize" target="_blank">drupal.org handbook page</a>.</p>';
danielebarchiesi@0 1229 $output .= '<p>How should the installation continue?</p>';
danielebarchiesi@0 1230 $output .= '<ul>';
danielebarchiesi@0 1231 $output .= '<li><a href="install.php?profile=' . $profilename . '">Reload the language selection page after adding translations</a></li>';
danielebarchiesi@0 1232 $output .= '<li><a href="install.php?profile=' . $profilename . '&amp;locale=en">Continue installation in English</a></li>';
danielebarchiesi@0 1233 $output .= '</ul>';
danielebarchiesi@0 1234 }
danielebarchiesi@0 1235 else {
danielebarchiesi@0 1236 include_once DRUPAL_ROOT . '/includes/form.inc';
danielebarchiesi@0 1237 $elements = drupal_get_form('install_select_locale_form', $locales, $profilename);
danielebarchiesi@0 1238 $output = drupal_render($elements);
danielebarchiesi@0 1239 }
danielebarchiesi@0 1240 return $output;
danielebarchiesi@0 1241 }
danielebarchiesi@0 1242 // One language, but not an interactive installation. Assume the user
danielebarchiesi@0 1243 // knows what he is doing.
danielebarchiesi@0 1244 $locale = current($locales);
danielebarchiesi@0 1245 $install_state['parameters']['locale'] = $locale->name;
danielebarchiesi@0 1246 return;
danielebarchiesi@0 1247 }
danielebarchiesi@0 1248 else {
danielebarchiesi@0 1249 // Allow profile to pre-select the language, skipping the selection.
danielebarchiesi@0 1250 $function = $profilename . '_profile_details';
danielebarchiesi@0 1251 if (function_exists($function)) {
danielebarchiesi@0 1252 $details = $function();
danielebarchiesi@0 1253 if (isset($details['language'])) {
danielebarchiesi@0 1254 foreach ($locales as $locale) {
danielebarchiesi@0 1255 if ($details['language'] == $locale->name) {
danielebarchiesi@0 1256 $install_state['parameters']['locale'] = $locale->name;
danielebarchiesi@0 1257 return;
danielebarchiesi@0 1258 }
danielebarchiesi@0 1259 }
danielebarchiesi@0 1260 }
danielebarchiesi@0 1261 }
danielebarchiesi@0 1262
danielebarchiesi@0 1263 // We still don't have a locale, so display a form for selecting one.
danielebarchiesi@0 1264 // Only do this in the case of interactive installations, since this is
danielebarchiesi@0 1265 // not a real form with submit handlers (the database isn't even set up
danielebarchiesi@0 1266 // yet), rather just a convenience method for setting parameters in the
danielebarchiesi@0 1267 // URL.
danielebarchiesi@0 1268 if ($install_state['interactive']) {
danielebarchiesi@0 1269 drupal_set_title(st('Choose language'));
danielebarchiesi@0 1270 include_once DRUPAL_ROOT . '/includes/form.inc';
danielebarchiesi@0 1271 $elements = drupal_get_form('install_select_locale_form', $locales, $profilename);
danielebarchiesi@0 1272 return drupal_render($elements);
danielebarchiesi@0 1273 }
danielebarchiesi@0 1274 else {
danielebarchiesi@0 1275 throw new Exception(st('Sorry, you must select a language to continue the installation.'));
danielebarchiesi@0 1276 }
danielebarchiesi@0 1277 }
danielebarchiesi@0 1278 }
danielebarchiesi@0 1279 }
danielebarchiesi@0 1280
danielebarchiesi@0 1281 /**
danielebarchiesi@0 1282 * Form constructor for the language selection form.
danielebarchiesi@0 1283 *
danielebarchiesi@0 1284 * @ingroup forms
danielebarchiesi@0 1285 */
danielebarchiesi@0 1286 function install_select_locale_form($form, &$form_state, $locales, $profilename) {
danielebarchiesi@0 1287 include_once DRUPAL_ROOT . '/includes/iso.inc';
danielebarchiesi@0 1288 $languages = _locale_get_predefined_list();
danielebarchiesi@0 1289 foreach ($locales as $locale) {
danielebarchiesi@0 1290 $name = $locale->langcode;
danielebarchiesi@0 1291 if (isset($languages[$name])) {
danielebarchiesi@0 1292 $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : '');
danielebarchiesi@0 1293 }
danielebarchiesi@0 1294 $form['locale'][$locale->langcode] = array(
danielebarchiesi@0 1295 '#type' => 'radio',
danielebarchiesi@0 1296 '#return_value' => $locale->langcode,
danielebarchiesi@0 1297 '#default_value' => $locale->langcode == 'en' ? 'en' : '',
danielebarchiesi@0 1298 '#title' => $name . ($locale->langcode == 'en' ? ' ' . st('(built-in)') : ''),
danielebarchiesi@0 1299 '#parents' => array('locale')
danielebarchiesi@0 1300 );
danielebarchiesi@0 1301 }
danielebarchiesi@0 1302 if (count($locales) == 1) {
danielebarchiesi@0 1303 $form['help'] = array(
danielebarchiesi@0 1304 '#markup' => '<p><a href="install.php?profile=' . $profilename . '&amp;localize=true">' . st('Learn how to install Drupal in other languages') . '</a></p>',
danielebarchiesi@0 1305 );
danielebarchiesi@0 1306 }
danielebarchiesi@0 1307 $form['actions'] = array('#type' => 'actions');
danielebarchiesi@0 1308 $form['actions']['submit'] = array(
danielebarchiesi@0 1309 '#type' => 'submit',
danielebarchiesi@0 1310 '#value' => st('Save and continue'),
danielebarchiesi@0 1311 );
danielebarchiesi@0 1312 return $form;
danielebarchiesi@0 1313 }
danielebarchiesi@0 1314
danielebarchiesi@0 1315 /**
danielebarchiesi@0 1316 * Indicates that there are no profiles available.
danielebarchiesi@0 1317 */
danielebarchiesi@0 1318 function install_no_profile_error() {
danielebarchiesi@0 1319 drupal_set_title(st('No profiles available'));
danielebarchiesi@0 1320 return st('We were unable to find any installation profiles. Installation 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.');
danielebarchiesi@0 1321 }
danielebarchiesi@0 1322
danielebarchiesi@0 1323 /**
danielebarchiesi@0 1324 * Indicates that Drupal has already been installed.
danielebarchiesi@0 1325 */
danielebarchiesi@0 1326 function install_already_done_error() {
danielebarchiesi@0 1327 global $base_url;
danielebarchiesi@0 1328
danielebarchiesi@0 1329 drupal_set_title(st('Drupal already installed'));
danielebarchiesi@0 1330 return 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));
danielebarchiesi@0 1331 }
danielebarchiesi@0 1332
danielebarchiesi@0 1333 /**
danielebarchiesi@0 1334 * Loads information about the chosen profile during installation.
danielebarchiesi@0 1335 *
danielebarchiesi@0 1336 * @param $install_state
danielebarchiesi@0 1337 * An array of information about the current installation state. The loaded
danielebarchiesi@0 1338 * profile information will be added here, or an exception will be thrown if
danielebarchiesi@0 1339 * the profile cannot be loaded.
danielebarchiesi@0 1340 */
danielebarchiesi@0 1341 function install_load_profile(&$install_state) {
danielebarchiesi@0 1342 $profile_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.profile';
danielebarchiesi@0 1343 if (file_exists($profile_file)) {
danielebarchiesi@0 1344 include_once $profile_file;
danielebarchiesi@0 1345 $install_state['profile_info'] = install_profile_info($install_state['parameters']['profile'], $install_state['parameters']['locale']);
danielebarchiesi@0 1346 }
danielebarchiesi@0 1347 else {
danielebarchiesi@0 1348 throw new Exception(st('Sorry, the profile you have chosen cannot be loaded.'));
danielebarchiesi@0 1349 }
danielebarchiesi@0 1350 }
danielebarchiesi@0 1351
danielebarchiesi@0 1352 /**
danielebarchiesi@0 1353 * Performs a full bootstrap of Drupal during installation.
danielebarchiesi@0 1354 *
danielebarchiesi@0 1355 * @param $install_state
danielebarchiesi@0 1356 * An array of information about the current installation state.
danielebarchiesi@0 1357 */
danielebarchiesi@0 1358 function install_bootstrap_full(&$install_state) {
danielebarchiesi@0 1359 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
danielebarchiesi@0 1360 }
danielebarchiesi@0 1361
danielebarchiesi@0 1362 /**
danielebarchiesi@0 1363 * Installs required modules via a batch process.
danielebarchiesi@0 1364 *
danielebarchiesi@0 1365 * @param $install_state
danielebarchiesi@0 1366 * An array of information about the current installation state.
danielebarchiesi@0 1367 *
danielebarchiesi@0 1368 * @return
danielebarchiesi@0 1369 * The batch definition.
danielebarchiesi@0 1370 */
danielebarchiesi@0 1371 function install_profile_modules(&$install_state) {
danielebarchiesi@0 1372 $modules = variable_get('install_profile_modules', array());
danielebarchiesi@0 1373 $files = system_rebuild_module_data();
danielebarchiesi@0 1374 variable_del('install_profile_modules');
danielebarchiesi@0 1375
danielebarchiesi@0 1376 // Always install required modules first. Respect the dependencies between
danielebarchiesi@0 1377 // the modules.
danielebarchiesi@0 1378 $required = array();
danielebarchiesi@0 1379 $non_required = array();
danielebarchiesi@0 1380 // Although the profile module is marked as required, it needs to go after
danielebarchiesi@0 1381 // every dependency, including non-required ones. So clear its required
danielebarchiesi@0 1382 // flag for now to allow it to install late.
danielebarchiesi@0 1383 $files[$install_state['parameters']['profile']]->info['required'] = FALSE;
danielebarchiesi@0 1384 // Add modules that other modules depend on.
danielebarchiesi@0 1385 foreach ($modules as $module) {
danielebarchiesi@0 1386 if ($files[$module]->requires) {
danielebarchiesi@0 1387 $modules = array_merge($modules, array_keys($files[$module]->requires));
danielebarchiesi@0 1388 }
danielebarchiesi@0 1389 }
danielebarchiesi@0 1390 $modules = array_unique($modules);
danielebarchiesi@0 1391 foreach ($modules as $module) {
danielebarchiesi@0 1392 if (!empty($files[$module]->info['required'])) {
danielebarchiesi@0 1393 $required[$module] = $files[$module]->sort;
danielebarchiesi@0 1394 }
danielebarchiesi@0 1395 else {
danielebarchiesi@0 1396 $non_required[$module] = $files[$module]->sort;
danielebarchiesi@0 1397 }
danielebarchiesi@0 1398 }
danielebarchiesi@0 1399 arsort($required);
danielebarchiesi@0 1400 arsort($non_required);
danielebarchiesi@0 1401
danielebarchiesi@0 1402 $operations = array();
danielebarchiesi@0 1403 foreach ($required + $non_required as $module => $weight) {
danielebarchiesi@0 1404 $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
danielebarchiesi@0 1405 }
danielebarchiesi@0 1406 $batch = array(
danielebarchiesi@0 1407 'operations' => $operations,
danielebarchiesi@0 1408 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_distribution_name())),
danielebarchiesi@0 1409 'error_message' => st('The installation has encountered an error.'),
danielebarchiesi@0 1410 'finished' => '_install_profile_modules_finished',
danielebarchiesi@0 1411 );
danielebarchiesi@0 1412 return $batch;
danielebarchiesi@0 1413 }
danielebarchiesi@0 1414
danielebarchiesi@0 1415 /**
danielebarchiesi@0 1416 * Imports languages via a batch process during installation.
danielebarchiesi@0 1417 *
danielebarchiesi@0 1418 * @param $install_state
danielebarchiesi@0 1419 * An array of information about the current installation state.
danielebarchiesi@0 1420 *
danielebarchiesi@0 1421 * @return
danielebarchiesi@0 1422 * The batch definition, if there are language files to import.
danielebarchiesi@0 1423 */
danielebarchiesi@0 1424 function install_import_locales(&$install_state) {
danielebarchiesi@0 1425 include_once DRUPAL_ROOT . '/includes/locale.inc';
danielebarchiesi@0 1426 $install_locale = $install_state['parameters']['locale'];
danielebarchiesi@0 1427
danielebarchiesi@0 1428 include_once DRUPAL_ROOT . '/includes/iso.inc';
danielebarchiesi@0 1429 $predefined = _locale_get_predefined_list();
danielebarchiesi@0 1430 if (!isset($predefined[$install_locale])) {
danielebarchiesi@0 1431 // Drupal does not know about this language, so we prefill its values with
danielebarchiesi@0 1432 // our best guess. The user will be able to edit afterwards.
danielebarchiesi@0 1433 locale_add_language($install_locale, $install_locale, $install_locale, LANGUAGE_LTR, '', '', TRUE, TRUE);
danielebarchiesi@0 1434 }
danielebarchiesi@0 1435 else {
danielebarchiesi@0 1436 // A known predefined language, details will be filled in properly.
danielebarchiesi@0 1437 locale_add_language($install_locale, NULL, NULL, NULL, '', '', TRUE, TRUE);
danielebarchiesi@0 1438 }
danielebarchiesi@0 1439
danielebarchiesi@0 1440 // Collect files to import for this language.
danielebarchiesi@0 1441 $batch = locale_batch_by_language($install_locale, NULL);
danielebarchiesi@0 1442 if (!empty($batch)) {
danielebarchiesi@0 1443 // Remember components we cover in this batch set.
danielebarchiesi@0 1444 variable_set('install_locale_batch_components', $batch['#components']);
danielebarchiesi@0 1445 return $batch;
danielebarchiesi@0 1446 }
danielebarchiesi@0 1447 }
danielebarchiesi@0 1448
danielebarchiesi@0 1449 /**
danielebarchiesi@0 1450 * Form constructor for a form to configure the new site.
danielebarchiesi@0 1451 *
danielebarchiesi@0 1452 * @param $install_state
danielebarchiesi@0 1453 * An array of information about the current installation state.
danielebarchiesi@0 1454 *
danielebarchiesi@0 1455 * @see install_configure_form_validate()
danielebarchiesi@0 1456 * @see install_configure_form_submit()
danielebarchiesi@0 1457 * @ingroup forms
danielebarchiesi@0 1458 */
danielebarchiesi@0 1459 function install_configure_form($form, &$form_state, &$install_state) {
danielebarchiesi@0 1460 drupal_set_title(st('Configure site'));
danielebarchiesi@0 1461
danielebarchiesi@0 1462 // Warn about settings.php permissions risk
danielebarchiesi@0 1463 $settings_dir = conf_path();
danielebarchiesi@0 1464 $settings_file = $settings_dir . '/settings.php';
danielebarchiesi@0 1465 // Check that $_POST is empty so we only show this message when the form is
danielebarchiesi@0 1466 // first displayed, not on the next page after it is submitted. (We do not
danielebarchiesi@0 1467 // want to repeat it multiple times because it is a general warning that is
danielebarchiesi@0 1468 // not related to the rest of the installation process; it would also be
danielebarchiesi@0 1469 // especially out of place on the last page of the installer, where it would
danielebarchiesi@0 1470 // distract from the message that the Drupal installation has completed
danielebarchiesi@0 1471 // successfully.)
danielebarchiesi@0 1472 if (empty($_POST) && (!drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) {
danielebarchiesi@0 1473 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, consult the <a href="@handbook_url">online handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'warning');
danielebarchiesi@0 1474 }
danielebarchiesi@0 1475
danielebarchiesi@0 1476 drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
danielebarchiesi@0 1477 // Add JavaScript time zone detection.
danielebarchiesi@0 1478 drupal_add_js('misc/timezone.js');
danielebarchiesi@0 1479 // We add these strings as settings because JavaScript translation does not
danielebarchiesi@0 1480 // work during installation.
danielebarchiesi@0 1481 drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting');
danielebarchiesi@0 1482 drupal_add_js('jQuery(function () { Drupal.cleanURLsInstallCheck(); });', 'inline');
danielebarchiesi@0 1483 // Add JS to show / hide the 'Email administrator about site updates' elements
danielebarchiesi@0 1484 drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline');
danielebarchiesi@0 1485 // Build menu to allow clean URL check.
danielebarchiesi@0 1486 menu_rebuild();
danielebarchiesi@0 1487
danielebarchiesi@0 1488 // Cache a fully-built schema. This is necessary for any invocation of
danielebarchiesi@0 1489 // index.php because: (1) setting cache table entries requires schema
danielebarchiesi@0 1490 // information, (2) that occurs during bootstrap before any module are
danielebarchiesi@0 1491 // loaded, so (3) if there is no cached schema, drupal_get_schema() will
danielebarchiesi@0 1492 // try to generate one but with no loaded modules will return nothing.
danielebarchiesi@0 1493 //
danielebarchiesi@0 1494 // This logically could be done during the 'install_finished' task, but the
danielebarchiesi@0 1495 // clean URL check requires it now.
danielebarchiesi@0 1496 drupal_get_schema(NULL, TRUE);
danielebarchiesi@0 1497
danielebarchiesi@0 1498 // Return the form.
danielebarchiesi@0 1499 return _install_configure_form($form, $form_state, $install_state);
danielebarchiesi@0 1500 }
danielebarchiesi@0 1501
danielebarchiesi@0 1502 /**
danielebarchiesi@0 1503 * Installation task; import remaining languages via a batch process.
danielebarchiesi@0 1504 *
danielebarchiesi@0 1505 * @param $install_state
danielebarchiesi@0 1506 * An array of information about the current installation state.
danielebarchiesi@0 1507 *
danielebarchiesi@0 1508 * @return
danielebarchiesi@0 1509 * The batch definition, if there are language files to import.
danielebarchiesi@0 1510 */
danielebarchiesi@0 1511 function install_import_locales_remaining(&$install_state) {
danielebarchiesi@0 1512 include_once DRUPAL_ROOT . '/includes/locale.inc';
danielebarchiesi@0 1513 // Collect files to import for this language. Skip components already covered
danielebarchiesi@0 1514 // in the initial batch set.
danielebarchiesi@0 1515 $install_locale = $install_state['parameters']['locale'];
danielebarchiesi@0 1516 $batch = locale_batch_by_language($install_locale, NULL, variable_get('install_locale_batch_components', array()));
danielebarchiesi@0 1517 // Remove temporary variable.
danielebarchiesi@0 1518 variable_del('install_locale_batch_components');
danielebarchiesi@0 1519 return $batch;
danielebarchiesi@0 1520 }
danielebarchiesi@0 1521
danielebarchiesi@0 1522 /**
danielebarchiesi@0 1523 * Finishes importing files at end of installation.
danielebarchiesi@0 1524 *
danielebarchiesi@0 1525 * @param $install_state
danielebarchiesi@0 1526 * An array of information about the current installation state.
danielebarchiesi@0 1527 *
danielebarchiesi@0 1528 * @return
danielebarchiesi@0 1529 * A message informing the user that the installation is complete.
danielebarchiesi@0 1530 */
danielebarchiesi@0 1531 function install_finished(&$install_state) {
danielebarchiesi@0 1532 drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_distribution_name())), PASS_THROUGH);
danielebarchiesi@0 1533 $messages = drupal_set_message();
danielebarchiesi@0 1534 $output = '<p>' . st('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())) . '</p>';
danielebarchiesi@0 1535 $output .= '<p>' . (isset($messages['error']) ? st('Review the messages above before visiting <a href="@url">your new site</a>.', array('@url' => url(''))) : st('<a href="@url">Visit your new site</a>.', array('@url' => url('')))) . '</p>';
danielebarchiesi@0 1536
danielebarchiesi@0 1537 // Flush all caches to ensure that any full bootstraps during the installer
danielebarchiesi@0 1538 // do not leave stale cached data, and that any content types or other items
danielebarchiesi@0 1539 // registered by the installation profile are registered correctly.
danielebarchiesi@0 1540 drupal_flush_all_caches();
danielebarchiesi@0 1541
danielebarchiesi@0 1542 // Remember the profile which was used.
danielebarchiesi@0 1543 variable_set('install_profile', drupal_get_profile());
danielebarchiesi@0 1544
danielebarchiesi@0 1545 // Installation profiles are always loaded last
danielebarchiesi@0 1546 db_update('system')
danielebarchiesi@0 1547 ->fields(array('weight' => 1000))
danielebarchiesi@0 1548 ->condition('type', 'module')
danielebarchiesi@0 1549 ->condition('name', drupal_get_profile())
danielebarchiesi@0 1550 ->execute();
danielebarchiesi@0 1551
danielebarchiesi@0 1552 // Cache a fully-built schema.
danielebarchiesi@0 1553 drupal_get_schema(NULL, TRUE);
danielebarchiesi@0 1554
danielebarchiesi@0 1555 // Run cron to populate update status tables (if available) so that users
danielebarchiesi@0 1556 // will be warned if they've installed an out of date Drupal version.
danielebarchiesi@0 1557 // Will also trigger indexing of profile-supplied content or feeds.
danielebarchiesi@0 1558 drupal_cron_run();
danielebarchiesi@0 1559
danielebarchiesi@0 1560 return $output;
danielebarchiesi@0 1561 }
danielebarchiesi@0 1562
danielebarchiesi@0 1563 /**
danielebarchiesi@0 1564 * Batch callback for batch installation of modules.
danielebarchiesi@0 1565 */
danielebarchiesi@0 1566 function _install_module_batch($module, $module_name, &$context) {
danielebarchiesi@0 1567 // Install and enable the module right away, so that the module will be
danielebarchiesi@0 1568 // loaded by drupal_bootstrap in subsequent batch requests, and other
danielebarchiesi@0 1569 // modules possibly depending on it can safely perform their installation
danielebarchiesi@0 1570 // steps.
danielebarchiesi@0 1571 module_enable(array($module), FALSE);
danielebarchiesi@0 1572 $context['results'][] = $module;
danielebarchiesi@0 1573 $context['message'] = st('Installed %module module.', array('%module' => $module_name));
danielebarchiesi@0 1574 }
danielebarchiesi@0 1575
danielebarchiesi@0 1576 /**
danielebarchiesi@0 1577 * 'Finished' callback for module installation batch.
danielebarchiesi@0 1578 */
danielebarchiesi@0 1579 function _install_profile_modules_finished($success, $results, $operations) {
danielebarchiesi@0 1580 // Flush all caches to complete the module installation process. Subsequent
danielebarchiesi@0 1581 // installation tasks will now have full access to the profile's modules.
danielebarchiesi@0 1582 drupal_flush_all_caches();
danielebarchiesi@0 1583 }
danielebarchiesi@0 1584
danielebarchiesi@0 1585 /**
danielebarchiesi@0 1586 * Checks installation requirements and reports any errors.
danielebarchiesi@0 1587 */
danielebarchiesi@0 1588 function install_check_requirements($install_state) {
danielebarchiesi@0 1589 $profile = $install_state['parameters']['profile'];
danielebarchiesi@0 1590
danielebarchiesi@0 1591 // Check the profile requirements.
danielebarchiesi@0 1592 $requirements = drupal_check_profile($profile);
danielebarchiesi@0 1593
danielebarchiesi@0 1594 // If Drupal is not set up already, we need to create a settings file.
danielebarchiesi@0 1595 if (!$install_state['settings_verified']) {
danielebarchiesi@0 1596 $writable = FALSE;
danielebarchiesi@0 1597 $conf_path = './' . conf_path(FALSE, TRUE);
danielebarchiesi@0 1598 $settings_file = $conf_path . '/settings.php';
danielebarchiesi@0 1599 $default_settings_file = './sites/default/default.settings.php';
danielebarchiesi@0 1600 $file = $conf_path;
danielebarchiesi@0 1601 $exists = FALSE;
danielebarchiesi@0 1602 // Verify that the directory exists.
danielebarchiesi@0 1603 if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
danielebarchiesi@0 1604 // Check if a settings.php file already exists.
danielebarchiesi@0 1605 $file = $settings_file;
danielebarchiesi@0 1606 if (drupal_verify_install_file($settings_file, FILE_EXIST)) {
danielebarchiesi@0 1607 // If it does, make sure it is writable.
danielebarchiesi@0 1608 $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
danielebarchiesi@0 1609 $exists = TRUE;
danielebarchiesi@0 1610 }
danielebarchiesi@0 1611 }
danielebarchiesi@0 1612
danielebarchiesi@0 1613 // If default.settings.php does not exist, or is not readable, throw an
danielebarchiesi@0 1614 // error.
danielebarchiesi@0 1615 if (!drupal_verify_install_file($default_settings_file, FILE_EXIST|FILE_READABLE)) {
danielebarchiesi@0 1616 $requirements['default settings file exists'] = array(
danielebarchiesi@0 1617 'title' => st('Default settings file'),
danielebarchiesi@0 1618 'value' => st('The default settings file does not exist.'),
danielebarchiesi@0 1619 'severity' => REQUIREMENT_ERROR,
danielebarchiesi@0 1620 'description' => st('The @drupal installer requires that the %default-file file not be modified in any way from the original download.', array('@drupal' => drupal_install_profile_distribution_name(), '%default-file' => $default_settings_file)),
danielebarchiesi@0 1621 );
danielebarchiesi@0 1622 }
danielebarchiesi@0 1623 // Otherwise, if settings.php does not exist yet, we can try to copy
danielebarchiesi@0 1624 // default.settings.php to create it.
danielebarchiesi@0 1625 elseif (!$exists) {
danielebarchiesi@0 1626 $copied = drupal_verify_install_file($conf_path, FILE_EXIST|FILE_WRITABLE, 'dir') && @copy($default_settings_file, $settings_file);
danielebarchiesi@0 1627 if ($copied) {
danielebarchiesi@0 1628 // If the new settings file has the same owner as default.settings.php,
danielebarchiesi@0 1629 // this means default.settings.php is owned by the webserver user.
danielebarchiesi@0 1630 // This is an inherent security weakness because it allows a malicious
danielebarchiesi@0 1631 // webserver process to append arbitrary PHP code and then execute it.
danielebarchiesi@0 1632 // However, it is also a common configuration on shared hosting, and
danielebarchiesi@0 1633 // there is nothing Drupal can do to prevent it. In this situation,
danielebarchiesi@0 1634 // having settings.php also owned by the webserver does not introduce
danielebarchiesi@0 1635 // any additional security risk, so we keep the file in place.
danielebarchiesi@0 1636 if (fileowner($default_settings_file) === fileowner($settings_file)) {
danielebarchiesi@0 1637 $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
danielebarchiesi@0 1638 $exists = TRUE;
danielebarchiesi@0 1639 }
danielebarchiesi@0 1640 // If settings.php and default.settings.php have different owners, this
danielebarchiesi@0 1641 // probably means the server is set up "securely" (with the webserver
danielebarchiesi@0 1642 // running as its own user, distinct from the user who owns all the
danielebarchiesi@0 1643 // Drupal PHP files), although with either a group or world writable
danielebarchiesi@0 1644 // sites directory. Keeping settings.php owned by the webserver would
danielebarchiesi@0 1645 // therefore introduce a security risk. It would also cause a usability
danielebarchiesi@0 1646 // problem, since site owners who do not have root access to the file
danielebarchiesi@0 1647 // system would be unable to edit their settings file later on. We
danielebarchiesi@0 1648 // therefore must delete the file we just created and force the
danielebarchiesi@0 1649 // administrator to log on to the server and create it manually.
danielebarchiesi@0 1650 else {
danielebarchiesi@0 1651 $deleted = @drupal_unlink($settings_file);
danielebarchiesi@0 1652 // We expect deleting the file to be successful (since we just
danielebarchiesi@0 1653 // created it ourselves above), but if it fails somehow, we set a
danielebarchiesi@0 1654 // variable so we can display a one-time error message to the
danielebarchiesi@0 1655 // administrator at the bottom of the requirements list. We also try
danielebarchiesi@0 1656 // to make the file writable, to eliminate any conflicting error
danielebarchiesi@0 1657 // messages in the requirements list.
danielebarchiesi@0 1658 $exists = !$deleted;
danielebarchiesi@0 1659 if ($exists) {
danielebarchiesi@0 1660 $settings_file_ownership_error = TRUE;
danielebarchiesi@0 1661 $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
danielebarchiesi@0 1662 }
danielebarchiesi@0 1663 }
danielebarchiesi@0 1664 }
danielebarchiesi@0 1665 }
danielebarchiesi@0 1666
danielebarchiesi@0 1667 // If settings.php does not exist, throw an error.
danielebarchiesi@0 1668 if (!$exists) {
danielebarchiesi@0 1669 $requirements['settings file exists'] = array(
danielebarchiesi@0 1670 'title' => st('Settings file'),
danielebarchiesi@0 1671 'value' => st('The settings file does not exist.'),
danielebarchiesi@0 1672 'severity' => REQUIREMENT_ERROR,
danielebarchiesi@0 1673 'description' => st('The @drupal installer requires that you create a settings file as part of the installation process. Copy the %default_file file to %file. More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>.', array('@drupal' => drupal_install_profile_distribution_name(), '%file' => $file, '%default_file' => $default_settings_file, '@install_txt' => base_path() . 'INSTALL.txt')),
danielebarchiesi@0 1674 );
danielebarchiesi@0 1675 }
danielebarchiesi@0 1676 else {
danielebarchiesi@0 1677 $requirements['settings file exists'] = array(
danielebarchiesi@0 1678 'title' => st('Settings file'),
danielebarchiesi@0 1679 'value' => st('The %file file exists.', array('%file' => $file)),
danielebarchiesi@0 1680 );
danielebarchiesi@0 1681 // If settings.php is not writable, throw an error.
danielebarchiesi@0 1682 if (!$writable) {
danielebarchiesi@0 1683 $requirements['settings file writable'] = array(
danielebarchiesi@0 1684 'title' => st('Settings file'),
danielebarchiesi@0 1685 'value' => st('The settings file is not writable.'),
danielebarchiesi@0 1686 'severity' => REQUIREMENT_ERROR,
danielebarchiesi@0 1687 'description' => st('The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.', array('@drupal' => drupal_install_profile_distribution_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')),
danielebarchiesi@0 1688 );
danielebarchiesi@0 1689 }
danielebarchiesi@0 1690 else {
danielebarchiesi@0 1691 $requirements['settings file'] = array(
danielebarchiesi@0 1692 'title' => st('Settings file'),
danielebarchiesi@0 1693 'value' => st('The settings file is writable.'),
danielebarchiesi@0 1694 );
danielebarchiesi@0 1695 }
danielebarchiesi@0 1696 if (!empty($settings_file_ownership_error)) {
danielebarchiesi@0 1697 $requirements['settings file ownership'] = array(
danielebarchiesi@0 1698 'title' => st('Settings file'),
danielebarchiesi@0 1699 'value' => st('The settings file is owned by the web server.'),
danielebarchiesi@0 1700 'severity' => REQUIREMENT_ERROR,
danielebarchiesi@0 1701 'description' => st('The @drupal installer failed to create a settings file with proper file ownership. Log on to your web server, remove the existing %file file, and create a new one by copying the %default_file file to %file. More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>. If you have problems with the file permissions on your server, consult the <a href="@handbook_url">online handbook</a>.', array('@drupal' => drupal_install_profile_distribution_name(), '%file' => $file, '%default_file' => $default_settings_file, '@install_txt' => base_path() . 'INSTALL.txt', '@handbook_url' => 'http://drupal.org/server-permissions')),
danielebarchiesi@0 1702 );
danielebarchiesi@0 1703 }
danielebarchiesi@0 1704 }
danielebarchiesi@0 1705 }
danielebarchiesi@0 1706 return $requirements;
danielebarchiesi@0 1707 }
danielebarchiesi@0 1708
danielebarchiesi@0 1709 /**
danielebarchiesi@0 1710 * Form constructor for a site configuration form.
danielebarchiesi@0 1711 *
danielebarchiesi@0 1712 * @param $install_state
danielebarchiesi@0 1713 * An array of information about the current installation state.
danielebarchiesi@0 1714 *
danielebarchiesi@0 1715 * @see install_configure_form()
danielebarchiesi@0 1716 * @see install_configure_form_validate()
danielebarchiesi@0 1717 * @see install_configure_form_submit()
danielebarchiesi@0 1718 * @ingroup forms
danielebarchiesi@0 1719 */
danielebarchiesi@0 1720 function _install_configure_form($form, &$form_state, &$install_state) {
danielebarchiesi@0 1721 include_once DRUPAL_ROOT . '/includes/locale.inc';
danielebarchiesi@0 1722
danielebarchiesi@0 1723 $form['site_information'] = array(
danielebarchiesi@0 1724 '#type' => 'fieldset',
danielebarchiesi@0 1725 '#title' => st('Site information'),
danielebarchiesi@0 1726 '#collapsible' => FALSE,
danielebarchiesi@0 1727 );
danielebarchiesi@0 1728 $form['site_information']['site_name'] = array(
danielebarchiesi@0 1729 '#type' => 'textfield',
danielebarchiesi@0 1730 '#title' => st('Site name'),
danielebarchiesi@0 1731 '#required' => TRUE,
danielebarchiesi@0 1732 '#weight' => -20,
danielebarchiesi@0 1733 );
danielebarchiesi@0 1734 $form['site_information']['site_mail'] = array(
danielebarchiesi@0 1735 '#type' => 'textfield',
danielebarchiesi@0 1736 '#title' => st('Site e-mail address'),
danielebarchiesi@0 1737 '#default_value' => ini_get('sendmail_from'),
danielebarchiesi@0 1738 '#description' => st("Automated e-mails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these e-mails from being flagged as spam."),
danielebarchiesi@0 1739 '#required' => TRUE,
danielebarchiesi@0 1740 '#weight' => -15,
danielebarchiesi@0 1741 );
danielebarchiesi@0 1742 $form['admin_account'] = array(
danielebarchiesi@0 1743 '#type' => 'fieldset',
danielebarchiesi@0 1744 '#title' => st('Site maintenance account'),
danielebarchiesi@0 1745 '#collapsible' => FALSE,
danielebarchiesi@0 1746 );
danielebarchiesi@0 1747
danielebarchiesi@0 1748 $form['admin_account']['account']['#tree'] = TRUE;
danielebarchiesi@0 1749 $form['admin_account']['account']['name'] = array('#type' => 'textfield',
danielebarchiesi@0 1750 '#title' => st('Username'),
danielebarchiesi@0 1751 '#maxlength' => USERNAME_MAX_LENGTH,
danielebarchiesi@0 1752 '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'),
danielebarchiesi@0 1753 '#required' => TRUE,
danielebarchiesi@0 1754 '#weight' => -10,
danielebarchiesi@0 1755 '#attributes' => array('class' => array('username')),
danielebarchiesi@0 1756 );
danielebarchiesi@0 1757
danielebarchiesi@0 1758 $form['admin_account']['account']['mail'] = array('#type' => 'textfield',
danielebarchiesi@0 1759 '#title' => st('E-mail address'),
danielebarchiesi@0 1760 '#maxlength' => EMAIL_MAX_LENGTH,
danielebarchiesi@0 1761 '#required' => TRUE,
danielebarchiesi@0 1762 '#weight' => -5,
danielebarchiesi@0 1763 );
danielebarchiesi@0 1764 $form['admin_account']['account']['pass'] = array(
danielebarchiesi@0 1765 '#type' => 'password_confirm',
danielebarchiesi@0 1766 '#required' => TRUE,
danielebarchiesi@0 1767 '#size' => 25,
danielebarchiesi@0 1768 '#weight' => 0,
danielebarchiesi@0 1769 );
danielebarchiesi@0 1770
danielebarchiesi@0 1771 $form['server_settings'] = array(
danielebarchiesi@0 1772 '#type' => 'fieldset',
danielebarchiesi@0 1773 '#title' => st('Server settings'),
danielebarchiesi@0 1774 '#collapsible' => FALSE,
danielebarchiesi@0 1775 );
danielebarchiesi@0 1776
danielebarchiesi@0 1777 $countries = country_get_list();
danielebarchiesi@0 1778 $form['server_settings']['site_default_country'] = array(
danielebarchiesi@0 1779 '#type' => 'select',
danielebarchiesi@0 1780 '#title' => st('Default country'),
danielebarchiesi@0 1781 '#empty_value' => '',
danielebarchiesi@0 1782 '#default_value' => variable_get('site_default_country', NULL),
danielebarchiesi@0 1783 '#options' => $countries,
danielebarchiesi@0 1784 '#description' => st('Select the default country for the site.'),
danielebarchiesi@0 1785 '#weight' => 0,
danielebarchiesi@0 1786 );
danielebarchiesi@0 1787
danielebarchiesi@0 1788 $form['server_settings']['date_default_timezone'] = array(
danielebarchiesi@0 1789 '#type' => 'select',
danielebarchiesi@0 1790 '#title' => st('Default time zone'),
danielebarchiesi@0 1791 '#default_value' => date_default_timezone_get(),
danielebarchiesi@0 1792 '#options' => system_time_zones(),
danielebarchiesi@0 1793 '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'),
danielebarchiesi@0 1794 '#weight' => 5,
danielebarchiesi@0 1795 '#attributes' => array('class' => array('timezone-detect')),
danielebarchiesi@0 1796 );
danielebarchiesi@0 1797
danielebarchiesi@0 1798 $form['server_settings']['clean_url'] = array(
danielebarchiesi@0 1799 '#type' => 'hidden',
danielebarchiesi@0 1800 '#default_value' => 0,
danielebarchiesi@0 1801 '#attributes' => array('id' => 'edit-clean-url', 'class' => array('install')),
danielebarchiesi@0 1802 );
danielebarchiesi@0 1803
danielebarchiesi@0 1804 $form['update_notifications'] = array(
danielebarchiesi@0 1805 '#type' => 'fieldset',
danielebarchiesi@0 1806 '#title' => st('Update notifications'),
danielebarchiesi@0 1807 '#collapsible' => FALSE,
danielebarchiesi@0 1808 );
danielebarchiesi@0 1809 $form['update_notifications']['update_status_module'] = array(
danielebarchiesi@0 1810 '#type' => 'checkboxes',
danielebarchiesi@0 1811 '#options' => array(
danielebarchiesi@0 1812 1 => st('Check for updates automatically'),
danielebarchiesi@0 1813 2 => st('Receive e-mail notifications'),
danielebarchiesi@0 1814 ),
danielebarchiesi@0 1815 '#default_value' => array(1, 2),
danielebarchiesi@0 1816 '#description' => st('The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to <a href="@drupal">Drupal.org</a>.', array('@drupal' => 'http://drupal.org')),
danielebarchiesi@0 1817 '#weight' => 15,
danielebarchiesi@0 1818 );
danielebarchiesi@0 1819
danielebarchiesi@0 1820 $form['actions'] = array('#type' => 'actions');
danielebarchiesi@0 1821 $form['actions']['submit'] = array(
danielebarchiesi@0 1822 '#type' => 'submit',
danielebarchiesi@0 1823 '#value' => st('Save and continue'),
danielebarchiesi@0 1824 '#weight' => 15,
danielebarchiesi@0 1825 );
danielebarchiesi@0 1826
danielebarchiesi@0 1827 return $form;
danielebarchiesi@0 1828 }
danielebarchiesi@0 1829
danielebarchiesi@0 1830 /**
danielebarchiesi@0 1831 * Form validation handler for install_configure_form().
danielebarchiesi@0 1832 *
danielebarchiesi@0 1833 * @see install_configure_form_submit()
danielebarchiesi@0 1834 */
danielebarchiesi@0 1835 function install_configure_form_validate($form, &$form_state) {
danielebarchiesi@0 1836 if ($error = user_validate_name($form_state['values']['account']['name'])) {
danielebarchiesi@0 1837 form_error($form['admin_account']['account']['name'], $error);
danielebarchiesi@0 1838 }
danielebarchiesi@0 1839 if ($error = user_validate_mail($form_state['values']['account']['mail'])) {
danielebarchiesi@0 1840 form_error($form['admin_account']['account']['mail'], $error);
danielebarchiesi@0 1841 }
danielebarchiesi@0 1842 if ($error = user_validate_mail($form_state['values']['site_mail'])) {
danielebarchiesi@0 1843 form_error($form['site_information']['site_mail'], $error);
danielebarchiesi@0 1844 }
danielebarchiesi@0 1845 }
danielebarchiesi@0 1846
danielebarchiesi@0 1847 /**
danielebarchiesi@0 1848 * Form submission handler for install_configure_form().
danielebarchiesi@0 1849 *
danielebarchiesi@0 1850 * @see install_configure_form_validate()
danielebarchiesi@0 1851 */
danielebarchiesi@0 1852 function install_configure_form_submit($form, &$form_state) {
danielebarchiesi@0 1853 global $user;
danielebarchiesi@0 1854
danielebarchiesi@0 1855 variable_set('site_name', $form_state['values']['site_name']);
danielebarchiesi@0 1856 variable_set('site_mail', $form_state['values']['site_mail']);
danielebarchiesi@0 1857 variable_set('date_default_timezone', $form_state['values']['date_default_timezone']);
danielebarchiesi@0 1858 variable_set('site_default_country', $form_state['values']['site_default_country']);
danielebarchiesi@0 1859
danielebarchiesi@0 1860 // Enable update.module if this option was selected.
danielebarchiesi@0 1861 if ($form_state['values']['update_status_module'][1]) {
danielebarchiesi@0 1862 module_enable(array('update'), FALSE);
danielebarchiesi@0 1863
danielebarchiesi@0 1864 // Add the site maintenance account's email address to the list of
danielebarchiesi@0 1865 // addresses to be notified when updates are available, if selected.
danielebarchiesi@0 1866 if ($form_state['values']['update_status_module'][2]) {
danielebarchiesi@0 1867 variable_set('update_notify_emails', array($form_state['values']['account']['mail']));
danielebarchiesi@0 1868 }
danielebarchiesi@0 1869 }
danielebarchiesi@0 1870
danielebarchiesi@0 1871 // We precreated user 1 with placeholder values. Let's save the real values.
danielebarchiesi@0 1872 $account = user_load(1);
danielebarchiesi@0 1873 $merge_data = array('init' => $form_state['values']['account']['mail'], 'roles' => !empty($account->roles) ? $account->roles : array(), 'status' => 1, 'timezone' => $form_state['values']['date_default_timezone']);
danielebarchiesi@0 1874 user_save($account, array_merge($form_state['values']['account'], $merge_data));
danielebarchiesi@0 1875 // Load global $user and perform final login tasks.
danielebarchiesi@0 1876 $user = user_load(1);
danielebarchiesi@0 1877 user_login_finalize();
danielebarchiesi@0 1878
danielebarchiesi@0 1879 if (isset($form_state['values']['clean_url'])) {
danielebarchiesi@0 1880 variable_set('clean_url', $form_state['values']['clean_url']);
danielebarchiesi@0 1881 }
danielebarchiesi@0 1882
danielebarchiesi@0 1883 // Record when this install ran.
danielebarchiesi@0 1884 variable_set('install_time', $_SERVER['REQUEST_TIME']);
danielebarchiesi@0 1885 }