123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914 |
- <?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']);
- }
|