12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925 |
- <?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;
-
-
- $connection = Database::getConnection();
- if ($connection->utf8mb4IsConfigurable() && $connection->utf8mb4IsActive()) {
- variable_set('drupal_all_databases_are_utf8mb4', 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']);
- }
|