install.core.inc
<?php
define('INSTALL_TASK_SKIP', 1);
define('INSTALL_TASK_RUN_IF_REACHED', 2);
define('INSTALL_TASK_RUN_IF_NOT_COMPLETED', 3);
function install_drupal($settings = array()) {
global $install_state;
$interactive = empty($settings);
$install_state = $settings + array('interactive' => $interactive) + install_state_defaults();
try {
install_begin_request($install_state);
$output = install_run_tasks($install_state);
}
catch (Exception $e) {
if ($install_state['interactive']) {
install_display_output($e->getMessage(), $install_state);
}
else {
throw $e;
}
}
if ($install_state['interactive']) {
if ($install_state['parameters_changed']) {
install_goto(install_redirect_url($install_state));
}
elseif (isset($output)) {
install_display_output($output, $install_state);
}
}
}
function install_state_defaults() {
$defaults = array(
'active_task' => NULL,
'completed_task' => NULL,
'database_tables_exist' => FALSE,
'forms' => array(),
'installation_finished' => FALSE,
'interactive' => TRUE,
'locales' => array(),
'parameters' => array(),
'parameters_changed' => FALSE,
'profile_info' => array(),
'profiles' => array(),
'server' => array(),
'settings_verified' => FALSE,
'stop_page_request' => FALSE,
'task_not_complete' => FALSE,
'tasks_performed' => array(),
);
return $defaults;
}
function install_begin_request(&$install_state) {
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
if (!$install_state['interactive']) {
drupal_override_server_variables($install_state['server']);
}
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
exit;
}
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
global $conf;
require_once DRUPAL_ROOT . '/modules/system/system.install';
require_once DRUPAL_ROOT . '/includes/common.inc';
require_once DRUPAL_ROOT . '/includes/file.inc';
require_once DRUPAL_ROOT . '/includes/install.inc';
require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
include_once DRUPAL_ROOT . '/includes/module.inc';
include_once DRUPAL_ROOT . '/includes/session.inc';
drupal_language_initialize();
include_once DRUPAL_ROOT . '/includes/entity.inc';
require_once DRUPAL_ROOT . '/includes/ajax.inc';
$module_list['system']['filename'] = 'modules/system/system.module';
$module_list['user']['filename'] = 'modules/user/user.module';
module_list(TRUE, FALSE, FALSE, $module_list);
drupal_load('module', 'system');
drupal_load('module', 'user');
require_once DRUPAL_ROOT . '/includes/cache.inc';
require_once DRUPAL_ROOT . '/includes/cache-install.inc';
$conf['cache_default_class'] = 'DrupalFakeCache';
if ($install_state['interactive']) {
drupal_maintenance_theme();
}
$install_state['settings_verified'] = install_verify_settings();
if ($install_state['settings_verified']) {
require_once DRUPAL_ROOT . '/includes/database/database.inc';
$task = install_verify_completed_task();
}
else {
$task = NULL;
if (!empty($GLOBALS['db_url'])) {
throw new Exception(install_already_done_error());
}
}
$install_state['completed_task'] = $task;
$install_state['database_tables_exist'] = !empty($task);
$install_state['parameters'] += $_GET;
if (!empty($install_state['parameters']['profile'])) {
$install_state['parameters']['profile'] = preg_replace('/[^a-zA-Z_0-9]/', '', $install_state['parameters']['profile']);
}
if (!empty($install_state['parameters']['locale'])) {
$install_state['parameters']['locale'] = preg_replace('/[^a-zA-Z_0-9\-]/', '', $install_state['parameters']['locale']);
}
}
function install_run_tasks(&$install_state) {
do {
$tasks_to_perform = install_tasks_to_perform($install_state);
reset($tasks_to_perform);
$task_name = key($tasks_to_perform);
$task = array_shift($tasks_to_perform);
$install_state['active_task'] = $task_name;
$original_parameters = $install_state['parameters'];
$output = install_run_task($task, $install_state);
$install_state['parameters_changed'] = ($install_state['parameters'] != $original_parameters);
if (!$install_state['task_not_complete']) {
$install_state['tasks_performed'][] = $task_name;
$install_state['installation_finished'] = empty($tasks_to_perform);
if ($install_state['database_tables_exist'] && ($task['run'] == INSTALL_TASK_RUN_IF_NOT_COMPLETED || $install_state['installation_finished'])) {
drupal_install_initialize_database();
variable_set('install_task', $install_state['installation_finished'] ? 'done' : $task_name);
}
}
$finished = empty($tasks_to_perform) || ($install_state['interactive'] && (isset($output) || $install_state['parameters_changed'] || $install_state['stop_page_request']));
} while (!$finished);
return $output;
}
function install_run_task($task, &$install_state) {
$function = $task['function'];
if ($task['type'] == 'form') {
require_once DRUPAL_ROOT . '/includes/form.inc';
if ($install_state['interactive']) {
$form_state = array(
'build_info' => array('args' => array(&$install_state)),
'no_redirect' => TRUE,
);
$form = drupal_build_form($function, $form_state);
if (empty($form_state['executed'])) {
$install_state['task_not_complete'] = TRUE;
return drupal_render($form);
}
return;
}
else {
$form_state = array('values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array());
drupal_form_submit($function, $form_state, $install_state);
$errors = form_get_errors();
if (!empty($errors)) {
throw new Exception(implode("\n", $errors));
}
}
}
elseif ($task['type'] == 'batch') {
$current_batch = variable_get('install_current_batch');
if (!$install_state['interactive'] || !$current_batch) {
$batch = $function($install_state);
if (empty($batch)) {
return;
}
batch_set($batch);
if ($install_state['interactive']) {
variable_set('install_current_batch', $function);
}
else {
$batch =& batch_get();
$batch['progressive'] = FALSE;
}
batch_process(install_redirect_url($install_state), install_full_redirect_url($install_state));
}
elseif ($current_batch == $function) {
include_once DRUPAL_ROOT . '/includes/batch.inc';
$output = _batch_page();
if ($output === FALSE) {
variable_del('install_current_batch');
return;
}
else {
$install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;
return $output;
}
}
}
else {
return $function($install_state);
}
}
function install_tasks_to_perform($install_state) {
$tasks = install_tasks($install_state);
foreach ($tasks as $name => $task) {
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)) {
unset($tasks[$name]);
}
if (!empty($install_state['completed_task']) && $name == $install_state['completed_task']) {
$completed_task_found = TRUE;
}
}
return $tasks;
}
function install_tasks($install_state) {
$needs_translations = count($install_state['locales']) > 1 && !empty($install_state['parameters']['locale']) && $install_state['parameters']['locale'] != 'en';
$tasks = array(
'install_select_profile' => array(
'display_name' => st('Choose profile'),
'display' => count($install_state['profiles']) != 1,
'run' => INSTALL_TASK_RUN_IF_REACHED,
),
'install_select_locale' => array(
'display_name' => st('Choose language'),
'run' => INSTALL_TASK_RUN_IF_REACHED,
),
'install_load_profile' => array(
'run' => INSTALL_TASK_RUN_IF_REACHED,
),
'install_verify_requirements' => array(
'display_name' => st('Verify requirements'),
),
'install_settings_form' => array(
'display_name' => st('Set up database'),
'type' => 'form',
'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
),
'install_system_module' => array(
),
'install_bootstrap_full' => array(
'run' => INSTALL_TASK_RUN_IF_REACHED,
),
'install_profile_modules' => array(
'display_name' => count($install_state['profiles']) == 1 ? st('Install site') : st('Install profile'),
'type' => 'batch',
),
'install_import_locales' => array(
'display_name' => st('Set up translations'),
'display' => $needs_translations,
'type' => 'batch',
'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
),
'install_configure_form' => array(
'display_name' => st('Configure site'),
'type' => 'form',
),
);
if (!empty($install_state['parameters']['profile'])) {
$function = $install_state['parameters']['profile'] . '_install_tasks';
if (function_exists($function)) {
$result = $function($install_state);
if (is_array($result)) {
$tasks += $result;
}
}
}
$tasks += array(
'install_import_locales_remaining' => array(
'display_name' => st('Finish translations'),
'display' => $needs_translations,
'type' => 'batch',
'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
),
'install_finished' => array(
'display_name' => st('Finished'),
),
);
if (!empty($install_state['parameters']['profile'])) {
$profile_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.profile';
if (is_file($profile_file)) {
include_once $profile_file;
$function = $install_state['parameters']['profile'] . '_install_tasks_alter';
if (function_exists($function)) {
$function($tasks, $install_state);
}
}
}
foreach ($tasks as $task_name => &$task) {
$task += array(
'display_name' => NULL,
'display' => !empty($task['display_name']),
'type' => 'normal',
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
'function' => $task_name,
);
}
return $tasks;
}
function install_tasks_to_display($install_state) {
$displayed_tasks = array();
foreach (install_tasks($install_state) as $name => $task) {
if ($task['display']) {
$displayed_tasks[$name] = $task['display_name'];
}
}
return $displayed_tasks;
}
function install_redirect_url($install_state) {
return 'install.php?' . drupal_http_build_query($install_state['parameters']);
}
function install_full_redirect_url($install_state) {
global $base_url;
return $base_url . '/' . install_redirect_url($install_state);
}
function install_display_output($output, $install_state) {
drupal_page_header();
if (isset($install_state['active_task'])) {
$active_task = $install_state['installation_finished'] ? NULL : $install_state['active_task'];
drupal_add_region_content('sidebar_first', theme('task_list', array('items' => install_tasks_to_display($install_state), 'active' => $active_task)));
}
print theme($install_state['database_tables_exist'] ? 'maintenance_page' : 'install_page', array('content' => $output));
exit;
}
function install_verify_requirements(&$install_state) {
$requirements = install_check_requirements($install_state);
$requirements += drupal_verify_profile($install_state);
$severity = drupal_requirements_severity($requirements);
if ($severity == REQUIREMENT_ERROR) {
if ($install_state['interactive']) {
drupal_set_title(st('Requirements problem'));
$status_report = theme('status_report', array('requirements' => $requirements));
$status_report .= st('Check the error messages and <a href="!url">proceed with the installation</a>.', array('!url' => check_url(request_uri())));
return $status_report;
}
else {
$failures = array();
foreach ($requirements as $requirement) {
if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
$failures[] = $requirement['title'] . ': ' . $requirement['value'] . "\n\n" . $requirement['description'];
}
}
throw new Exception(implode("\n\n", $failures));
}
}
}
function install_system_module(&$install_state) {
drupal_install_system();
module_enable(array('user'), FALSE);
$modules = $install_state['profile_info']['dependencies'];
$modules[] = drupal_get_profile();
variable_set('install_profile_modules', array_diff($modules, array('system')));
$install_state['database_tables_exist'] = TRUE;
}
function install_verify_completed_task() {
try {
if ($result = db_query("SELECT value FROM {variable} WHERE name = :name", array('name' => 'install_task'))) {
$task = unserialize($result->fetchField());
}
}
catch (Exception $e) {
}
if (isset($task)) {
if ($task == 'done') {
throw new Exception(install_already_done_error());
}
return $task;
}
}
function install_verify_settings() {
global $db_prefix, $databases;
if (!empty($databases) && install_verify_pdo()) {
$database = $databases['default']['default'];
drupal_static_reset('conf_path');
$settings_file = './' . conf_path(FALSE) . '/settings.php';
$errors = install_database_errors($database, $settings_file);
if (empty($errors)) {
return TRUE;
}
}
return FALSE;
}
function install_verify_pdo() {
return extension_loaded('pdo');
}
function install_settings_form($form, &$form_state, &$install_state) {
global $databases, $db_prefix;
$profile = $install_state['parameters']['profile'];
$install_locale = $install_state['parameters']['locale'];
drupal_static_reset('conf_path');
$conf_path = './' . conf_path(FALSE);
$settings_file = $conf_path . '/settings.php';
$database = isset($databases['default']['default']) ? $databases['default']['default'] : array();
drupal_set_title(st('Database configuration'));
$drivers = drupal_detect_database_types();
$form['driver'] = array(
'#type' => 'radios',
'#title' => st('Database type'),
'#required' => TRUE,
'#options' => $drivers,
'#default_value' => !empty($database['driver']) ? $database['driver'] : current(array_keys($drivers)),
'#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_distribution_name())),
);
if (count($drivers) == 1) {
$form['driver']['#disabled'] = TRUE;
$form['driver']['#description'] .= ' ' . st('Your PHP configuration only supports the %driver database type so it has been automatically selected.', array('%driver' => current($drivers)));
}
$form['database'] = array(
'#type' => 'textfield',
'#title' => st('Database name'),
'#default_value' => empty($database['database']) ? '' : $database['database'],
'#size' => 45,
'#required' => TRUE,
'#description' => st('The name of the database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('@drupal' => drupal_install_profile_distribution_name())),
);
$form['username'] = array(
'#type' => 'textfield',
'#title' => st('Database username'),
'#default_value' => empty($database['username']) ? '' : $database['username'],
'#size' => 45,
);
$form['password'] = array(
'#type' => 'password',
'#title' => st('Database password'),
'#default_value' => empty($database['password']) ? '' : $database['password'],
'#size' => 45,
);
$form['advanced_options'] = array(
'#type' => 'fieldset',
'#title' => st('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider.")
);
$form['advanced_options']['host'] = array(
'#type' => 'textfield',
'#title' => st('Database host'),
'#default_value' => empty($database['host']) ? 'localhost' : $database['host'],
'#size' => 45,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => st('If your database is located on a different server, change this.'),
);
$form['advanced_options']['port'] = array(
'#type' => 'textfield',
'#title' => st('Database port'),
'#default_value' => empty($database['port']) ? '' : $database['port'],
'#size' => 45,
'#maxlength' => 5,
'#description' => st('If your database server is listening to a non-standard port, enter its number.'),
);
$db_prefix = ($profile == 'standard') ? 'drupal_' : $profile . '_';
$form['advanced_options']['db_prefix'] = array(
'#type' => 'textfield',
'#title' => st('Table prefix'),
'#default_value' => '',
'#size' => 45,
'#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_distribution_name(), '%prefix' => $db_prefix)),
);
$form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => st('Save and continue'),
);
$form['errors'] = array();
$form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);
$form['_database'] = array('#type' => 'value');
return $form;
}
function install_settings_form_validate($form, &$form_state) {
form_set_value($form['_database'], $form_state['values'], $form_state);
$errors = install_database_errors($form_state['values'], $form_state['values']['settings_file']);
foreach ($errors as $name => $message) {
form_set_error($name, $message);
}
}
function install_database_errors($database, $settings_file) {
global $databases;
$errors = array();
if (!empty($database['db_prefix']) && is_string($database['db_prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['db_prefix'])) {
$errors['db_prefix'] = st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $database['db_prefix']));
}
if (!empty($database['port']) && !is_numeric($database['port'])) {
$errors['db_port'] = st('Database port must be a number.');
}
$database_types = drupal_detect_database_types();
$driver = $database['driver'];
if (!isset($database_types[$driver])) {
$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' => $database['driver']));
}
else {
$databases['default']['default'] = $database;
Database::parseConnectionInfo();
try {
db_run_tasks($database['driver']);
}
catch (DatabaseTaskException $e) {
$errors[] = $e->getMessage();
}
}
return $errors;
}
function install_settings_form_submit($form, &$form_state) {
global $install_state;
$database = array_intersect_key($form_state['values']['_database'], array_flip(array('driver', 'database', 'username', 'password', 'host', 'port')));
$settings['databases'] = array(
'value' => array('default' => array('default' => $database)),
'required' => TRUE,
);
$settings['db_prefix'] = array(
'value' => $form_state['values']['db_prefix'],
'required' => TRUE,
);
$settings['drupal_hash_salt'] = array(
'value' => sha1(drupal_random_bytes(64)),
'required' => TRUE,
);
drupal_rewrite_settings($settings);
$install_state['settings_verified'] = TRUE;
$install_state['completed_task'] = install_verify_completed_task();
}
function install_find_profiles() {
return file_scan_directory('./profiles', '/\.profile$/', array('key' => 'name'));
}
function install_select_profile(&$install_state) {
$install_state['profiles'] += install_find_profiles();
if (empty($install_state['parameters']['profile'])) {
$profile = _install_select_profile($install_state['profiles']);
if (empty($profile)) {
if ($install_state['interactive']) {
include_once DRUPAL_ROOT . '/includes/form.inc';
drupal_set_title(st('Select an installation profile'));
$form = drupal_get_form('install_select_profile_form', $install_state['profiles']);
return drupal_render($form);
}
else {
throw new Exception(install_no_profile_error());
}
}
else {
$install_state['parameters']['profile'] = $profile;
}
}
}
function _install_select_profile($profiles) {
if (sizeof($profiles) == 0) {
throw new Exception(install_no_profile_error());
}
if (sizeof($profiles) == 1) {
$profile = array_pop($profiles);
require_once $profile->uri;
return $profile->name;
}
else {
foreach ($profiles as $profile) {
if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) {
return $profile->name;
}
}
}
}
function install_select_profile_form($form, &$form_state, $profile_files) {
$profiles = array();
$names = array();
foreach ($profile_files as $profile) {
include_once DRUPAL_ROOT . '/' . $profile->uri;
$details = install_profile_info($profile->name);
$profiles[$profile->name] = $details;
$name = isset($details['name']) ? $details['name'] : $profile->name;
$names[$profile->name] = $name;
}
natcasesort($names);
if (isset($names['minimal'])) {
$names = array('minimal' => $names['minimal']) + $names;
}
if (isset($names['standard'])) {
$names = array('standard' => $names['standard']) + $names;
}
foreach ($names as $profile => $name) {
$form['profile'][$name] = array(
'#type' => 'radio',
'#value' => 'standard',
'#return_value' => $profile,
'#title' => $name,
'#description' => isset($profiles[$profile]['description']) ? $profiles[$profile]['description'] : '',
'#parents' => array('profile'),
);
}
$form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Save and continue'),
);
return $form;
}
function install_find_locales($profilename) {
$locales = file_scan_directory('./profiles/' . $profilename . '/translations', '/\.po$/', array('recurse' => FALSE));
array_unshift($locales, (object) array('name' => 'en'));
return $locales;
}
function install_select_locale(&$install_state) {
$profilename = $install_state['parameters']['profile'];
$locales = install_find_locales($profilename);
$install_state['locales'] += $locales;
if (!empty($_POST['locale'])) {
foreach ($locales as $locale) {
if ($_POST['locale'] == $locale->name) {
$install_state['parameters']['locale'] = $locale->name;
return;
}
}
}
if (empty($install_state['parameters']['locale'])) {
if (count($locales) == 1) {
if ($profilename == 'standard' && $install_state['interactive']) {
drupal_set_title(st('Choose language'));
if (!empty($install_state['parameters']['localize'])) {
$output = '<p>' . st('With the addition of an appropriate translation package, this installer is capable of proceeding in another language of your choice. To install and use Drupal in a language other than English:') . '</p>';
$output .= '<ul><li>' . st('Determine if <a href="@translations" target="_blank">a translation of this Drupal version</a> is available in your language of choice. A translation is provided via a translation package; each translation package enables the display of a specific version of Drupal in a specific language. Not all languages are available for every version of Drupal.', array('@translations' => 'http://drupal.org/project/translations')) . '</li>';
$output .= '<li>' . st('If an alternative translation package of your choice is available, download and extract its contents to your Drupal root directory.') . '</li>';
$output .= '<li>' . st('Return to choose language using the second link below and select your desired language from the displayed list. Reloading the page allows the list to automatically adjust to the presence of new translation packages.') . '</li>';
$output .= '</ul><p>' . st('Alternatively, to install and use Drupal in English, or to defer the selection of an alternative language until after installation, select the first link below.') . '</p>';
$output .= '<p>' . st('How should the installation continue?') . '</p>';
$output .= '<ul><li><a href="install.php?profile=' . $profilename . '&locale=en">' . st('Continue installation in English') . '</a></li><li><a href="install.php?profile=' . $profilename . '">' . st('Return to choose a language') . '</a></li></ul>';
}
else {
include_once DRUPAL_ROOT . '/includes/form.inc';
$output = drupal_render(drupal_get_form('install_select_locale_form', $locales, $profilename));
}
return $output;
}
$locale = current($locales);
$install_state['parameters']['locale'] = $locale->name;
return;
}
else {
$function = $profilename . '_profile_details';
if (function_exists($function)) {
$details = $function();
if (isset($details['language'])) {
foreach ($locales as $locale) {
if ($details['language'] == $locale->name) {
$install_state['parameters']['locale'] = $locale->name;
return;
}
}
}
}
if ($install_state['interactive']) {
drupal_set_title(st('Choose language'));
include_once DRUPAL_ROOT . '/includes/form.inc';
return drupal_render(drupal_get_form('install_select_locale_form', $locales, $profilename));
}
else {
throw new Exception(st('Sorry, you must select a language to continue the installation.'));
}
}
}
}
function install_select_locale_form($form, &$form_state, $locales, $profilename = 'standard') {
include_once DRUPAL_ROOT . '/includes/iso.inc';
$languages = _locale_get_predefined_list();
foreach ($locales as $locale) {
$name = $locale->name;
if (isset($languages[$name])) {
$name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : '');
}
$form['locale'][$locale->name] = array(
'#type' => 'radio',
'#return_value' => $locale->name,
'#default_value' => $locale->name == 'en' ? 'en' : '',
'#title' => $name . ($locale->name == 'en' ? ' ' . st('(built-in)') : ''),
'#parents' => array('locale')
);
}
if ($profilename == 'standard') {
$form['help'] = array(
'#markup' => '<p><a href="install.php?profile=' . $profilename . '&localize=true">' . st('Learn how to install Drupal in other languages') . '</a></p>',
);
}
$form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Save and continue'),
);
return $form;
}
function install_no_profile_error() {
drupal_set_title(st('No profiles available'));
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.');
}
function install_already_done_error() {
global $base_url;
drupal_set_title(st('Drupal already installed'));
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));
}
function install_load_profile(&$install_state) {
$profile_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.profile';
if (is_file($profile_file)) {
include_once $profile_file;
$install_state['profile_info'] = install_profile_info($install_state['parameters']['profile'], $install_state['parameters']['locale']);
}
else {
throw new Exception(st('Sorry, the profile you have chosen cannot be loaded.'));
}
}
function install_bootstrap_full(&$install_state) {
$messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : '';
drupal_install_initialize_database();
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$_SESSION['messages'] = $messages;
}
function install_profile_modules(&$install_state) {
$modules = variable_get('install_profile_modules', array());
$files = system_rebuild_module_data();
variable_del('install_profile_modules');
$operations = array();
foreach ($modules as $module) {
$operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
}
$batch = array(
'operations' => $operations,
'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_distribution_name())),
'error_message' => st('The installation has encountered an error.'),
);
return $batch;
}
function install_import_locales(&$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
$install_locale = $install_state['parameters']['locale'];
locale_add_language($install_locale, NULL, NULL, NULL, '', NULL, 1, TRUE);
$batch = locale_batch_by_language($install_locale, NULL);
if (!empty($batch)) {
variable_set('install_locale_batch_components', $batch['#components']);
return $batch;
}
}
function install_configure_form($form, &$form_state, &$install_state) {
if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) {
throw new Exception(install_already_done_error());
}
drupal_set_title(st('Configure site'));
$settings_dir = './' . conf_path();
$settings_file = $settings_dir . '/settings.php';
if (!drupal_verify_install_file($settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) {
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')), 'error');
}
else {
drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file)));
}
drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
drupal_add_js('misc/timezone.js');
drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting');
drupal_add_js('jQuery(function () { Drupal.cleanURLsInstallCheck(); });', 'inline');
drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline');
menu_rebuild();
drupal_get_schema(NULL, TRUE);
return _install_configure_form($form, $form_state, $install_state);
}
function install_import_locales_remaining(&$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
$install_locale = $install_state['parameters']['locale'];
$batch = locale_batch_by_language($install_locale, NULL, variable_get('install_locale_batch_components', array()));
variable_del('install_locale_batch_components');
return $batch;
}
function install_finished(&$install_state) {
drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_distribution_name())), PASS_THROUGH);
$messages = drupal_set_message();
$output = '<p>' . st('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())) . '</p>';
$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>';
drupal_static_reset('_system_rebuild_theme_data');
system_rebuild_module_data();
system_rebuild_theme_data();
drupal_flush_all_caches();
actions_synchronize();
variable_set('install_profile', drupal_get_profile());
db_update('system')
->fields(array('weight' => 1000))
->condition('type', 'module')
->condition('name', drupal_get_profile())
->execute();
drupal_get_schema(NULL, TRUE);
drupal_cron_run();
return $output;
}
function _install_module_batch($module, $module_name, &$context) {
module_enable(array($module), FALSE);
$context['results'][] = $module;
$context['message'] = st('Installed %module module.', array('%module' => $module_name));
}
function install_check_requirements($install_state) {
$profile = $install_state['parameters']['profile'];
$requirements = drupal_check_profile($profile);
if (!$install_state['settings_verified']) {
$writable = FALSE;
$conf_path = './' . conf_path(FALSE, TRUE);
$settings_file = $conf_path . '/settings.php';
$file = $conf_path;
$exists = FALSE;
if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
$file = $settings_file;
if (drupal_verify_install_file($settings_file, FILE_EXIST)) {
$exists = TRUE;
$writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
$exists = TRUE;
}
}
if (!$exists) {
$requirements['settings file exists'] = array(
'title' => st('Settings file'),
'value' => st('The settings file does not exist.'),
'severity' => REQUIREMENT_ERROR,
'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' => $conf_path . '/default.settings.php', '@install_txt' => base_path() . 'INSTALL.txt')),
);
}
else {
$requirements['settings file exists'] = array(
'title' => st('Settings file'),
'value' => st('The %file file exists.', array('%file' => $file)),
);
if (!$writable) {
$requirements['settings file writable'] = array(
'title' => st('Settings file'),
'value' => st('The settings file is not writable.'),
'severity' => REQUIREMENT_ERROR,
'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')),
);
}
else {
$requirements['settings file'] = array(
'title' => st('Settings file'),
'value' => st('Settings file is writable.'),
);
}
}
}
return $requirements;
}
function _install_configure_form($form, &$form_state, &$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
$form['site_information'] = array(
'#type' => 'fieldset',
'#title' => st('Site information'),
'#collapsible' => FALSE,
);
$form['site_information']['site_name'] = array(
'#type' => 'textfield',
'#title' => st('Site name'),
'#required' => TRUE,
'#weight' => -20,
);
$form['site_information']['site_mail'] = array(
'#type' => 'textfield',
'#title' => st('Site e-mail address'),
'#default_value' => ini_get('sendmail_from'),
'#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."),
'#required' => TRUE,
'#weight' => -15,
);
$form['admin_account'] = array(
'#type' => 'fieldset',
'#title' => st('Site maintenance account'),
'#collapsible' => FALSE,
);
$form['admin_account']['account']['#tree'] = TRUE;
$form['admin_account']['account']['name'] = array('#type' => 'textfield',
'#title' => st('Username'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'),
'#required' => TRUE,
'#weight' => -10,
'#attributes' => array('class' => array('username')),
);
$form['admin_account']['account']['mail'] = array('#type' => 'textfield',
'#title' => st('E-mail address'),
'#maxlength' => EMAIL_MAX_LENGTH,
'#required' => TRUE,
'#weight' => -5,
);
$form['admin_account']['account']['pass'] = array(
'#type' => 'password_confirm',
'#required' => TRUE,
'#size' => 25,
'#weight' => 0,
);
$form['server_settings'] = array(
'#type' => 'fieldset',
'#title' => st('Server settings'),
'#collapsible' => FALSE,
);
$countries = country_get_list();
$countries = array_merge(array('' => st('No default country')), $countries);
$form['server_settings']['site_default_country'] = array(
'#type' => 'select',
'#title' => t('Default country'),
'#default_value' => variable_get('site_default_country', ''),
'#options' => $countries,
'#description' => st('Select the default country for the site.'),
'#weight' => 0,
);
$form['server_settings']['date_default_timezone'] = array(
'#type' => 'select',
'#title' => st('Default time zone'),
'#default_value' => date_default_timezone_get(),
'#options' => system_time_zones(),
'#description' => st('By default, dates in this site will be displayed in the chosen time zone.'),
'#weight' => 5,
'#attributes' => array('class' => array('timezone-detect')),
);
$form['server_settings']['clean_url'] = array(
'#type' => 'hidden',
'#default_value' => 0,
'#attributes' => array('class' => array('install')),
);
$form['update_notifications'] = array(
'#type' => 'fieldset',
'#title' => st('Update notifications'),
'#collapsible' => FALSE,
);
$form['update_notifications']['update_status_module'] = array(
'#type' => 'checkboxes',
'#options' => array(
1 => st('Check for updates automatically'),
2 => st('Receive e-mail notifications'),
),
'#default_value' => array(1, 2),
'#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')),
'#weight' => 15,
);
$form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Save and continue'),
'#weight' => 15,
);
return $form;
}
function install_configure_form_validate($form, &$form_state) {
if ($error = user_validate_name($form_state['values']['account']['name'])) {
form_error($form['admin_account']['account']['name'], $error);
}
if ($error = user_validate_mail($form_state['values']['account']['mail'])) {
form_error($form['admin_account']['account']['mail'], $error);
}
if ($error = user_validate_mail($form_state['values']['site_mail'])) {
form_error($form['site_information']['site_mail'], $error);
}
}
function install_configure_form_submit($form, &$form_state) {
global $user;
variable_set('site_name', $form_state['values']['site_name']);
variable_set('site_mail', $form_state['values']['site_mail']);
variable_set('date_default_timezone', $form_state['values']['date_default_timezone']);
variable_set('site_default_country', $form_state['values']['site_default_country']);
if ($form_state['values']['update_status_module'][1]) {
module_enable(array('update'), FALSE);
if ($form_state['values']['update_status_module'][2]) {
variable_set('update_notify_emails', array($form_state['values']['account']['mail']));
}
}
variable_set('user_email_verification', FALSE);
$form_state['old_values'] = $form_state['values'];
$form_state['values'] = $form_state['values']['account'];
$account = user_load(1);
$merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 1);
user_save($account, array_merge($form_state['values'], $merge_data));
$user = user_load(1);
user_login_finalize();
$form_state['values'] = $form_state['old_values'];
unset($form_state['old_values']);
variable_set('user_email_verification', TRUE);
if (isset($form_state['values']['clean_url'])) {
variable_set('clean_url', $form_state['values']['clean_url']);
}
variable_set('install_time', $_SERVER['REQUEST_TIME']);
}