1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909 |
- <?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) {
-
- $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']);
- }
-
- 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';
-
-
-
-
-
- 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['databases']) || !empty($GLOBALS['db_url'])) {
- throw new Exception(install_already_done_error());
- }
- }
-
- $install_state['completed_task'] = $task;
- $install_state['database_tables_exist'] = !empty($task);
- }
- 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'])) {
- 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(),
-
-
-
- 'build_info' => array('args' => array(&$install_state)),
- );
- drupal_form_submit($function, $form_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'])) {
-
-
- $profile_install_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.install';
- if (file_exists($profile_install_file)) {
- include_once $profile_install_file;
- }
- $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 (file_exists($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();
-
-
-
-
-
- $noindex_meta_tag = array(
- '#tag' => 'meta',
- '#attributes' => array(
- 'name' => 'robots',
- 'content' => 'noindex, nofollow',
- ),
- );
- drupal_add_html_head($noindex_meta_tag, 'install_meta_robots');
-
-
-
- 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_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 || ($severity == REQUIREMENT_WARNING && empty($install_state['parameters']['continue']))) {
- 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(drupal_requirements_url($severity))));
- 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'];
- }
- }
- if (!empty($failures)) {
- throw new Exception(implode("\n\n", $failures));
- }
- }
- }
- }
- function install_system_module(&$install_state) {
-
- drupal_install_system();
-
-
-
-
-
-
-
- file_ensure_htaccess();
-
-
- 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 $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') && defined('PDO::ATTR_DEFAULT_FETCH_MODE');
- }
- function install_settings_form($form, &$form_state, &$install_state) {
- global $databases;
- $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_get_database_types();
- $drivers_keys = array_keys($drivers);
- $form['driver'] = array(
- '#type' => 'radios',
- '#title' => st('Database type'),
- '#required' => TRUE,
- '#default_value' => !empty($database['driver']) ? $database['driver'] : current($drivers_keys),
- '#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 a single database type, so it has been automatically selected.');
- }
-
- foreach ($drivers as $key => $driver) {
- $form['driver']['#options'][$key] = $driver->name();
- $form['settings'][$key] = $driver->getFormOptions($database);
- $form['settings'][$key]['#prefix'] = '<h2 class="js-hide">' . st('@driver_name settings', array('@driver_name' => $driver->name())) . '</h2>';
- $form['settings'][$key]['#type'] = 'container';
- $form['settings'][$key]['#tree'] = TRUE;
- $form['settings'][$key]['advanced_options']['#parents'] = array($key);
- $form['settings'][$key]['#states'] = array(
- 'visible' => array(
- ':input[name=driver]' => array('value' => $key),
- )
- );
- }
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['save'] = array(
- '#type' => 'submit',
- '#value' => st('Save and continue'),
- '#limit_validation_errors' => array(
- array('driver'),
- array(isset($form_state['input']['driver']) ? $form_state['input']['driver'] : current($drivers_keys)),
- ),
- '#submit' => array('install_settings_form_submit'),
- );
- $form['errors'] = array();
- $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);
- return $form;
- }
- function install_settings_form_validate($form, &$form_state) {
- $driver = $form_state['values']['driver'];
- $database = $form_state['values'][$driver];
- $database['driver'] = $driver;
-
-
- $database['prefix'] = $database['db_prefix'];
- unset($database['db_prefix']);
- $form_state['storage']['database'] = $database;
- $errors = install_database_errors($database, $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();
-
- $database_types = drupal_get_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' => $driver));
- }
- else {
-
- $errors += $database_types[$driver]->validateDatabaseSettings($database);
-
-
- $databases['default']['default'] = $database;
-
-
- Database::parseConnectionInfo();
- try {
- db_run_tasks($driver);
- }
- catch (DatabaseTaskException $e) {
-
-
-
- $errors[$driver . '][0'] = $e->getMessage();
- }
- }
- return $errors;
- }
- function install_settings_form_submit($form, &$form_state) {
- global $install_state;
-
- $settings['databases'] = array(
- 'value' => array('default' => array('default' => $form_state['storage']['database'])),
- 'required' => TRUE,
- );
- $settings['drupal_hash_salt'] = array(
- 'value' => drupal_random_key(),
- '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 DRUPAL_ROOT . '/' . $profile->uri;
- return $profile->name;
- }
- else {
- foreach ($profiles as $profile) {
- if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) {
- return $profile->name;
- }
- }
- }
-
-
- $exclusive_profile = NULL;
- foreach ($profiles as $profile) {
- $profile_info = install_profile_info($profile->name);
- if (!empty($profile_info['exclusive'])) {
- if (empty($exclusive_profile)) {
- $exclusive_profile = $profile->name;
- }
- else {
-
-
- return;
- }
- }
- }
- return $exclusive_profile;
- }
- 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);
-
-
- if ($details['hidden'] === TRUE) {
- continue;
- }
- $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' => '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'));
- foreach ($locales as $key => $locale) {
-
- $locales[$key]->langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $locale->name);
-
-
- if (strlen($locales[$key]->langcode) > 12) {
- unset($locales[$key]);
- }
- }
- 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->langcode) {
- $install_state['parameters']['locale'] = $locale->langcode;
- return;
- }
- }
- }
- if (empty($install_state['parameters']['locale'])) {
-
-
-
-
- if (count($locales) == 1) {
- if ($install_state['interactive']) {
- drupal_set_title(st('Choose language'));
- if (!empty($install_state['parameters']['localize'])) {
- $output = '<p>Follow these steps to translate Drupal into your language:</p>';
- $output .= '<ol>';
- $output .= '<li>Download a translation from the <a href="http://localize.drupal.org/download" target="_blank">translation server</a>.</li>';
- $output .= '<li>Place it into the following directory:
- <pre>
- /profiles/' . $profilename . '/translations/
- </pre></li>';
- $output .= '</ol>';
- $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>';
- $output .= '<p>How should the installation continue?</p>';
- $output .= '<ul>';
- $output .= '<li><a href="install.php?profile=' . $profilename . '">Reload the language selection page after adding translations</a></li>';
- $output .= '<li><a href="install.php?profile=' . $profilename . '&locale=en">Continue installation in English</a></li>';
- $output .= '</ul>';
- }
- else {
- include_once DRUPAL_ROOT . '/includes/form.inc';
- $elements = drupal_get_form('install_select_locale_form', $locales, $profilename);
- $output = drupal_render($elements);
- }
- 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';
- $elements = drupal_get_form('install_select_locale_form', $locales, $profilename);
- return drupal_render($elements);
- }
- 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) {
- include_once DRUPAL_ROOT . '/includes/iso.inc';
- $languages = _locale_get_predefined_list();
- foreach ($locales as $locale) {
- $name = $locale->langcode;
- if (isset($languages[$name])) {
- $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : '');
- }
- $form['locale'][$locale->langcode] = array(
- '#type' => 'radio',
- '#return_value' => $locale->langcode,
- '#default_value' => $locale->langcode == 'en' ? 'en' : '',
- '#title' => $name . ($locale->langcode == 'en' ? ' ' . st('(built-in)') : ''),
- '#parents' => array('locale')
- );
- }
- if (count($locales) == 1) {
- $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' => '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 (file_exists($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) {
- drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
- }
- function install_profile_modules(&$install_state) {
- $modules = variable_get('install_profile_modules', array());
- $files = system_rebuild_module_data();
- variable_del('install_profile_modules');
-
-
- $required = array();
- $non_required = array();
-
-
-
- $files[$install_state['parameters']['profile']]->info['required'] = FALSE;
-
- foreach ($modules as $module) {
- if ($files[$module]->requires) {
- $modules = array_merge($modules, array_keys($files[$module]->requires));
- }
- }
- $modules = array_unique($modules);
- foreach ($modules as $module) {
- if (!empty($files[$module]->info['required'])) {
- $required[$module] = $files[$module]->sort;
- }
- else {
- $non_required[$module] = $files[$module]->sort;
- }
- }
- arsort($required);
- arsort($non_required);
- $operations = array();
- foreach ($required + $non_required as $module => $weight) {
- $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.'),
- 'finished' => '_install_profile_modules_finished',
- );
- return $batch;
- }
- function install_import_locales(&$install_state) {
- include_once DRUPAL_ROOT . '/includes/locale.inc';
- $install_locale = $install_state['parameters']['locale'];
- include_once DRUPAL_ROOT . '/includes/iso.inc';
- $predefined = _locale_get_predefined_list();
- if (!isset($predefined[$install_locale])) {
-
-
- locale_add_language($install_locale, $install_locale, $install_locale, LANGUAGE_LTR, '', '', TRUE, TRUE);
- }
- else {
-
- locale_add_language($install_locale, NULL, NULL, NULL, '', '', TRUE, 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) {
- drupal_set_title(st('Configure site'));
-
- $settings_dir = conf_path();
- $settings_file = $settings_dir . '/settings.php';
-
-
-
-
-
-
-
- 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'))) {
- 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');
- }
- 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_flush_all_caches();
-
- 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_profile_modules_finished($success, $results, $operations) {
-
-
- drupal_flush_all_caches();
- }
- 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';
- $default_settings_file = './sites/default/default.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)) {
-
- $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
- $exists = TRUE;
- }
- }
-
-
- if (!drupal_verify_install_file($default_settings_file, FILE_EXIST|FILE_READABLE)) {
- $requirements['default settings file exists'] = array(
- 'title' => st('Default settings file'),
- 'value' => st('The default settings file does not exist.'),
- 'severity' => REQUIREMENT_ERROR,
- '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)),
- );
- }
-
-
- elseif (!$exists) {
- $copied = drupal_verify_install_file($conf_path, FILE_EXIST|FILE_WRITABLE, 'dir') && @copy($default_settings_file, $settings_file);
- if ($copied) {
-
-
-
-
-
-
-
-
- if (fileowner($default_settings_file) === fileowner($settings_file)) {
- $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
- $exists = TRUE;
- }
-
-
-
-
-
-
-
-
-
-
- else {
- $deleted = @drupal_unlink($settings_file);
-
-
-
-
-
-
- $exists = !$deleted;
- if ($exists) {
- $settings_file_ownership_error = TRUE;
- $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
- }
- }
- }
- }
-
- 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' => $default_settings_file, '@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('The settings file is writable.'),
- );
- }
- if (!empty($settings_file_ownership_error)) {
- $requirements['settings file ownership'] = array(
- 'title' => st('Settings file'),
- 'value' => st('The settings file is owned by the web server.'),
- 'severity' => REQUIREMENT_ERROR,
- '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')),
- );
- }
- }
- }
- 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();
- $form['server_settings']['site_default_country'] = array(
- '#type' => 'select',
- '#title' => st('Default country'),
- '#empty_value' => '',
- '#default_value' => variable_get('site_default_country', NULL),
- '#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('id' => 'edit-clean-url', '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' => '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']));
- }
- }
-
- $account = user_load(1);
- $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']);
- user_save($account, array_merge($form_state['values']['account'], $merge_data));
-
- $user = user_load(1);
- user_login_finalize();
- if (isset($form_state['values']['clean_url'])) {
- variable_set('clean_url', $form_state['values']['clean_url']);
- }
-
- variable_set('install_time', $_SERVER['REQUEST_TIME']);
- }
|