- <?php
- * @file
- * API functions for installing Backdrop.
- */
-
- * Do not run the task during the current installation request.
- *
- * This can be used to skip running an installation task when certain
- * conditions are met, even though the task may still show on the list of
- * installation tasks presented to the user. For example, the Backdrop installer
- * uses this flag to skip over the database configuration form when valid
- * database connection information is already available from settings.php. It
- * also uses this flag to skip language import tasks when the installation is
- * being performed in English.
- */
- define('INSTALL_TASK_SKIP', 1);
-
- * Run the task on each installation request until the database is set up.
- *
- * This is primarily used by the Backdrop installer for bootstrap-related tasks.
- */
- define('INSTALL_TASK_RUN_IF_REACHED', 2);
-
- * Global flag to indicate that a task should be run on each installation
- * request that reaches it, until the database is set up and we are able to
- * record the fact that it already ran.
- *
- * This is the default method for running tasks and should be used for most
- * tasks that occur after the database is set up; these tasks will then run
- * once and be marked complete once they are successfully finished. For
- * example, the Backdrop installer uses this flag for the batch installation of
- * modules on the new site, and also for the configuration form that collects
- * basic site information and sets up the site maintenance account.
- */
- define('INSTALL_TASK_RUN_IF_NOT_COMPLETED', 3);
-
- * The URI used to fetch the list of available translations from the
- * localization server.
- */
- define('INSTALL_AVAILABLE_TRANSLATIONS_URI', 'https://localize.backdropcms.org/translate/available-languages');
-
- * The server URL where the interface translation files can be downloaded.
- * Tokens in the pattern will be replaced by appropriate values for the
- * required translation file.
- */
- define('INSTALL_LOCALIZATION_SERVER_PATTERN', 'https://localize.backdropcms.org/files/l10n_packager/%core/%project/%project-%version.%language.po');
-
- * Installs Backdrop either interactively or via an array of passed-in settings.
- *
- * The Backdrop installation happens in a series of steps, which may be spread
- * out over multiple page requests. Each request begins by trying to determine
- * the last completed installation step (also known as a "task"), if one is
- * available from a previous request. Control is then passed to the task
- * handler, which processes the remaining tasks that need to be run until (a)
- * an error is thrown, (b) a new page needs to be displayed, or (c) the
- * installation finishes (whichever happens first).
- *
- * @param $settings
- * An optional array of installation settings. Leave this empty for a normal,
- * interactive, browser-based installation intended to occur over multiple
- * page requests. Alternatively, if an array of settings is passed in, the
- * installer will attempt to use it to perform the installation in a single
- * page request (optimized for the command line) and not send any output
- * intended for the web browser. See install_state_defaults() for a list of
- * elements that are allowed to appear in this array.
- *
- * @see install_state_defaults()
- *
- * @throws Exception
- */
- function install_backdrop($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);
- }
- }
- }
-
- * Returns an array of default settings for the global installation state.
- *
- * The installation state is initialized with these settings at the beginning
- * of each page request. They may evolve during the page request, but they are
- * initialized again once the next request begins.
- *
- * Non-interactive Backdrop installations can override some of these default
- * settings by passing in an array to the installation script, most notably
- * 'parameters' (which contains one-time parameters such as 'profile' and
- * 'langcode' that are normally passed in via the URL) and 'forms' (which can
- * be used to programmatically submit forms during the installation; the keys
- * of each element indicate the name of the installation task that the form
- * submission is for, and the values are used as the $form_state['values']
- * array that is passed on to the form submission via backdrop_form_submit()).
- *
- * @see backdrop_form_submit()
- */
- function install_state_defaults() {
- $defaults = array(
-
- 'active_task' => NULL,
-
-
- 'completed_task' => NULL,
-
- 'database_tables_exist' => FALSE,
-
-
-
-
-
- 'forms' => array(),
-
-
-
-
-
-
- 'installation_finished' => FALSE,
-
-
- 'interactive' => TRUE,
-
- 'translations' => 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;
- }
-
- * Begins an installation request, modifying the installation state as needed.
- *
- * This function performs commands that must run at the beginning of every page
- * request. It throws an exception if the installation should not proceed.
- *
- * @param array $install_state
- * An array of information about the current installation state. This is
- * modified with information gleaned from the beginning of the page request.
- *
- * @throws Exception
- */
- 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']['langcode'])) {
- $install_state['parameters']['langcode'] = preg_replace('/[^a-zA-Z_0-9\-]/', '', $install_state['parameters']['langcode']);
- }
-
-
- require_once BACKDROP_ROOT . '/core/includes/bootstrap.inc';
- if (!$install_state['interactive']) {
- backdrop_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;
- }
-
- backdrop_bootstrap(BACKDROP_BOOTSTRAP_CONFIGURATION);
-
- require_once BACKDROP_ROOT . '/core/modules/system/system.install';
- require_once BACKDROP_ROOT . '/core/includes/common.inc';
- require_once BACKDROP_ROOT . '/core/includes/file.inc';
- require_once BACKDROP_ROOT . '/core/includes/install.inc';
- require_once BACKDROP_ROOT . '/' . settings_get('path_inc', 'core/includes/path.inc');
-
-
- include_once BACKDROP_ROOT . '/core/includes/module.inc';
- include_once BACKDROP_ROOT . '/core/includes/session.inc';
- require_once BACKDROP_ROOT . '/core/includes/theme.inc';
- require_once BACKDROP_ROOT . '/core/includes/tablesort.inc';
-
- require_once BACKDROP_ROOT . '/core/includes/ajax.inc';
- $module_list['system']['filename'] = 'core/modules/system/system.module';
- $module_list['entity']['filename'] = 'core/modules/entity/entity.module';
- $module_list['user']['filename'] = 'core/modules/user/user.module';
- module_list(TRUE, FALSE, FALSE, $module_list);
- backdrop_load('module', 'system');
- backdrop_load('module', 'entity');
- backdrop_load('module', 'user');
-
-
-
-
-
-
-
-
-
-
- require_once BACKDROP_ROOT . '/core/includes/cache.inc';
- require_once BACKDROP_ROOT . '/core/includes/cache-install.inc';
- $GLOBALS['settings']['cache_default_class'] = 'BackdropFakeCache';
-
-
- backdrop_language_initialize();
-
-
-
-
-
-
- backdrop_maintenance_theme();
-
-
- $install_state['settings_verified'] = install_verify_settings();
-
- if ($install_state['settings_verified']) {
-
-
- require_once BACKDROP_ROOT . '/core/includes/database/database.inc';
-
-
- $task = install_verify_completed_task();
- }
- else {
- $task = NULL;
-
-
- if (!empty($GLOBALS['databases'])) {
- throw new Exception(install_already_done_error());
- }
- }
-
-
- $install_state['completed_task'] = $task;
- $install_state['database_tables_exist'] = !empty($task);
-
-
- $install_state['profiles'] += install_find_profiles();
- }
-
- * Runs all tasks for the current installation request.
- *
- * In the case of an interactive installation, all tasks will be attempted
- * until one is reached that has output which needs to be displayed to the
- * user, or until a page redirect is required. Otherwise, tasks will be
- * attempted until the installation is finished.
- *
- * @param array $install_state
- * An array of information about the current installation state. This is
- * passed along to each task, so it can be modified if necessary.
- *
- * @return
- * HTML output from the last completed 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'])) {
- state_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;
- }
-
- * Runs an individual installation task.
- *
- * @param $task
- * An array of information about the task to be run as returned by
- * hook_install_tasks().
- * @param array $install_state
- * An array of information about the current installation state. This is
- * passed in by reference so that it can be modified by the task.
- *
- * @return string|NULL
- * The output of the task function, if there is any.
- *
- * @throws Exception
- */
- function install_run_task($task, &$install_state) {
- $function = $task['function'];
-
- if ($task['type'] == 'form') {
- require_once BACKDROP_ROOT . '/core/includes/form.inc';
- if ($install_state['interactive']) {
-
-
-
- $form_state = array(
-
-
-
- 'build_info' => array('args' => array(&$install_state)),
- 'no_redirect' => TRUE,
-
-
-
- 'no_cache' => TRUE,
- );
- $form = backdrop_build_form($function, $form_state);
-
-
- if (empty($form_state['executed'])) {
- $install_state['task_not_complete'] = TRUE;
- return backdrop_render($form);
- }
-
-
- return NULL;
- }
- else {
-
-
-
- $form_state = array(
- 'values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array(),
-
-
-
- 'build_info' => array('args' => array(&$install_state)),
- );
- backdrop_form_submit($function, $form_state);
- $errors = form_get_errors();
- if (!empty($errors)) {
- throw new Exception(implode("\n", $errors));
- }
- }
- }
-
- elseif ($task['type'] == 'batch') {
-
-
- $current_batch = state_get('install_current_batch');
- if (!$install_state['interactive'] || !$current_batch) {
- $batch = $function($install_state);
- if (empty($batch)) {
-
-
- return NULL;
- }
- batch_set($batch);
-
-
-
- if ($install_state['interactive']) {
- state_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 BACKDROP_ROOT . '/core/includes/batch.inc';
- $output = _batch_page();
-
-
-
- if ($output === FALSE) {
-
- state_del('install_current_batch');
- return NULL;
- }
- else {
-
-
-
- $install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;
- return $output;
- }
- }
- }
-
- else {
-
- return $function($install_state);
- }
- }
-
- * Returns a list of tasks to perform during the current installation request.
- *
- * Note that the list of tasks can change based on the installation state as
- * the page request evolves (for example, if an installation profile hasn't
- * been selected yet, we don't yet know which profile tasks need to be run).
- *
- * You can override this using hook_install_tasks() or
- * hook_install_tasks_alter().
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * A list of tasks to be performed, with associated metadata as returned by
- * hook_install_tasks().
- */
- 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;
- }
-
- * Returns a list of all tasks the installer currently knows about.
- *
- * This function will return tasks regardless of whether or not they are
- * intended to run on the current page request. However, the list can change
- * based on the installation state (for example, if an installation profile
- * hasn't been selected yet, we don't yet know which profile tasks will be
- * available).
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * A list of tasks, with associated metadata.
- */
- function install_tasks($install_state) {
-
- $needs_translations = count($install_state['translations']) > 1 && !empty($install_state['parameters']['langcode']) && $install_state['parameters']['langcode'] != 'en';
-
-
- $hidden_profile_count = 0;
- foreach ($install_state['profiles'] as $profile) {
- $profile_info = install_profile_info($profile->name);
- $hidden_profile_count += empty($profile_info['hidden']);
- }
- $display_select_profile = $hidden_profile_count > 1 && count($install_state['profiles']) != 1;
-
-
-
-
- $needs_download = FALSE;
- if (isset($install_state['parameters']['langcode']) && $install_state['parameters']['langcode'] != 'en') {
- if (isset($install_state['translations'])) {
- $local_file_found = FALSE;
- foreach($install_state['translations'] as $translation_file) {
- if ($translation_file->langcode == $install_state['parameters']['langcode']) {
- $local_file_found = TRUE;
- break;
- }
- }
- $needs_download = !$local_file_found;
- }
- }
-
-
-
- $tasks = array(
- 'install_select_language' => array(
- 'display_name' => st('Choose language'),
- 'run' => INSTALL_TASK_RUN_IF_REACHED,
- ),
- 'install_download_translation' => array(
- 'run' => $needs_download ? INSTALL_TASK_RUN_IF_REACHED : INSTALL_TASK_SKIP,
- ),
- 'install_select_profile' => array(
- 'display_name' => st('Choose profile'),
- 'display' => $display_select_profile,
- 'run' => INSTALL_TASK_RUN_IF_REACHED,
- ),
- 'install_load_profile' => array(
- 'run' => INSTALL_TASK_RUN_IF_REACHED,
- ),
- 'install_verify_requirements' => array(
- 'display_name' => st('Verify site requirements'),
- ),
- 'install_hash_salt' => array(
- 'run' => INSTALL_TASK_RUN_IF_REACHED,
- ),
- 'install_settings_form' => array(
- 'display_name' => st('Set up your database'),
- 'type' => 'form',
- 'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
- ),
- 'install_config_location' => array(
- ),
- '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_translations' => 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 your site'),
- 'type' => 'form',
- ),
- );
-
-
- if (!empty($install_state['parameters']['profile'])) {
-
-
- $profile_install_file = _install_find_profile_file($install_state['parameters']['profile'], 'install');
- if ($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_translations_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(
- ),
- );
-
-
- if (!empty($install_state['parameters']['profile'])) {
- $profile_file = _install_find_profile_file($install_state['parameters']['profile']);
- if ($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;
- }
-
- * Returns a list of tasks that should be displayed to the end user.
- *
- * The output of this function is a list suitable for sending to
- * theme_task_list().
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * A list of tasks, with keys equal to the machine-readable task name and
- * values equal to the name that should be displayed.
- *
- * @see theme_task_list()
- */
- 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;
- }
-
- * Returns the URL that should be redirected to during an installation request.
- *
- * The output of this function is suitable for sending to install_goto().
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * The URL to redirect to.
- *
- * @see install_full_redirect_url()
- */
- function install_redirect_url($install_state) {
- return 'core/install.php?' . backdrop_http_build_query($install_state['parameters']);
- }
-
- * Returns the complete URL redirected to during an installation request.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * The complete URL to redirect to.
- *
- * @see install_redirect_url()
- */
- function install_full_redirect_url($install_state) {
- global $base_url;
- return $base_url . '/' . install_redirect_url($install_state);
- }
-
- * Displays themed installer output and ends the page request.
- *
- * Installation tasks should use backdrop_set_title() to set the desired page
- * title, but otherwise this function takes care of generating the page output
- * during every step of the installation.
- *
- * @param $output
- * The content to display on the main part of the page.
- * @param array $install_state
- * An array of information about the current installation state.
- */
- function install_display_output($output, $install_state) {
- backdrop_page_header();
-
-
-
-
-
-
- $noindex_meta_tag = array(
- '#tag' => 'meta',
- '#attributes' => array(
- 'name' => 'robots',
- 'content' => 'noindex, nofollow',
- ),
- );
- backdrop_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'];
- $task_list = theme('task_list', array('items' => install_tasks_to_display($install_state), 'active' => $active_task));
- }
- else {
- $task_list = NULL;
- }
- print theme('install_page', array('content' => $output, 'sidebar' => $task_list));
- exit;
- }
-
- * Verifies the requirements for installing Backdrop.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return string|NULL
- * A themed status report, or an exception if there are requirement errors.
- */
- function install_verify_requirements(&$install_state) {
-
- $requirements = install_check_requirements($install_state);
-
-
- $requirements += backdrop_verify_profile($install_state);
-
- return install_display_requirements($install_state, $requirements);
- }
-
- * Installation task; install the Backdrop system module.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- */
- function install_system_module(&$install_state) {
-
- backdrop_install_system();
-
-
-
-
-
-
-
-
- file_ensure_htaccess();
-
-
-
- module_enable(array('entity', 'user'), FALSE);
-
-
-
- $modules = $install_state['profile_info']['dependencies'];
-
-
-
- $modules[] = $install_state['parameters']['profile'];
-
- state_set('install_profile_modules', array_diff($modules, array('system')));
- $install_state['database_tables_exist'] = TRUE;
-
-
-
- $connection = Database::getConnection();
- if ($connection->utf8mb4IsActive()) {
- state_set('database_utf8mb4_active', TRUE);
- }
- }
-
- * Verifies and returns the last installation task that was completed.
- *
- * @return string|NULL
- * The last completed task, if there is one. An exception is thrown if Backdrop
- * is already installed.
- *
- * @throws Exception
- */
- function install_verify_completed_task() {
- try {
- if ($result = db_query("SELECT value FROM {state} 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;
- }
-
-
- return NULL;
- }
-
- * Verifies if UTF8 MB4 support is available in the database.
- *
- * @return bool
- */
- function install_verify_database_utf8mb4() {
- try {
- return Database::getConnection()->utf8mb4IsSupported();
- }
- catch (Exception $e) {
- return FALSE;
- }
- }
-
- * Verifies the existing settings in settings.php.
- */
- function install_verify_settings() {
- global $databases;
-
-
- if (!empty($databases) && install_verify_pdo()) {
- $database = $databases['default']['default'];
- backdrop_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;
- }
-
- * Verifies the PDO library.
- */
- function install_verify_pdo() {
-
-
-
-
-
- return extension_loaded('pdo') && defined('PDO::ATTR_DEFAULT_FETCH_MODE');
- }
-
- * Installation task; Rewrite settings.php to include hash salt.
- */
- function install_hash_salt() {
- global $settings;
-
- if (empty($settings['hash_salt'])) {
- $update_settings["settings['hash_salt']"] = array(
- 'value' => backdrop_random_key(),
- 'required' => TRUE,
- );
-
-
- try {
- backdrop_rewrite_settings($update_settings);
- }
- catch (Exception $e) {}
- }
- }
-
- * Installation task; Ensure config location is empty and writable, and (for
- * config stored in files, rewrite settings.php to include config directories.
- */
- function install_config_location(&$install_state) {
- backdrop_install_config_location();
- }
-
- * Form constructor for a form to configure and rewrite settings.php.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @see install_settings_form_validate()
- * @see install_settings_form_submit()
- * @ingroup forms
- */
- function install_settings_form($form, &$form_state, &$install_state) {
- global $databases;
-
-
-
- $form_state['no_cache'] = TRUE;
-
- backdrop_static_reset('conf_path');
- $settings_file = conf_path(FALSE) . '/settings.php';
- $database = isset($databases['default']['default']) ? $databases['default']['default'] : array();
-
- backdrop_set_title(st('Database configuration'));
-
- $form['driver'] = array(
- '#type' => 'hidden',
- '#required' => TRUE,
- '#value' => !empty($database['driver']) ? $database['driver'] : 'mysql',
- );
-
- $driver = backdrop_load_database_driver();
-
-
- $form['driver']['#options']['mysql'] = $driver->name();
- $form['settings']['mysql'] = $driver->getFormOptions($database);
- $form['settings']['mysql']['#prefix'] = '<h2 class="js-hide">' . st('@driver_name settings', array('@driver_name' => $driver->name())) . '</h2>';
- $form['settings']['mysql']['#type'] = 'container';
- $form['settings']['mysql']['#tree'] = TRUE;
- $form['settings']['mysql']['advanced_options']['#parents'] = array('mysql');
-
-
- if (isset($form_state['input']['mysql']['password'])) {
- $form['settings']['mysql']['password']['#attributes']['value'] = $form_state['input']['mysql']['password'];
- }
-
- $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'] : 'mysql'),
- ),
- '#submit' => array('install_settings_form_submit'),
- );
-
- $form['errors'] = array();
- $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);
-
- return $form;
- }
-
- * Form validation handler for install_settings_form().
- *
- * @see install_settings_form_submit()
- */
- function install_settings_form_validate($form, &$form_state) {
- $driver = $form_state['values']['driver'];
- $database = $form_state['values'][$driver];
- $database['driver'] = $driver;
-
- $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);
- }
- }
-
- * Checks a database connection and returns any errors.
- */
- function install_database_errors($database, $settings_file) {
- global $databases;
- $errors = array();
-
-
- $driver = $database['driver'];
- if (!$mysql_driver = backdrop_load_database_driver()) {
- $errors['driver'] = st("In your %settings_file file you have configured @profile to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@profile' => backdrop_install_profile_distribution_name(), '%driver' => $driver));
- }
- else {
-
- $errors += $mysql_driver->validateDatabaseSettings($database);
-
-
-
- $databases['default']['default'] = $database;
-
-
- Database::parseConnectionInfo();
-
- try {
- db_run_tasks($driver);
- }
- catch (DatabaseTaskException $e) {
-
-
-
- $errors[$driver . '][0'] = $e->getMessage();
- }
- }
- return $errors;
- }
-
- * Form submission handler for install_settings_form().
- *
- * @see install_settings_form_validate()
- */
- function install_settings_form_submit($form, &$form_state) {
- global $install_state;
-
-
- $db_settings = $form_state['storage']['database'];
- $settings['database'] = array(
- 'value' => $db_settings['driver'] . '://' . rawurlencode($db_settings['username']) . ':' . rawurlencode($db_settings['password']) . '@' . $db_settings['host'] . ($db_settings['port'] ? (':' . $db_settings['port']) : '') . '/' . rawurlencode($db_settings['database']),
- 'required' => TRUE,
- );
- $settings['database_prefix'] = array(
- 'value' => $db_settings['prefix'],
- );
- backdrop_rewrite_settings($settings);
-
-
- if (install_verify_database_utf8mb4()) {
- $settings = array();
- $settings['database_charset'] = array(
- 'value' => 'utf8mb4',
- 'required' => TRUE,
- );
- backdrop_rewrite_settings($settings);
- }
-
-
-
-
-
- $install_state['settings_verified'] = TRUE;
- $install_state['completed_task'] = install_verify_completed_task();
- }
-
- * Finds all .profile files.
- */
- function install_find_profiles() {
- $core_profiles = file_scan_directory('./core/profiles', '/\.profile$/', array('key' => 'name'));
- $root_profiles = file_scan_directory('./profiles', '/\.profile$/', array('key' => 'name'));
- return array_merge($core_profiles, $root_profiles);
- }
-
- * Selects which profile to install.
- *
- * @param array $install_state
- * An array of information about the current installation state. The chosen
- * profile will be added here, if it was not already selected previously, as
- * will a list of all available profiles.
- *
- * @return string
- * For interactive installations, a form allowing the profile to be selected,
- * if the user has a choice that needs to be made. Otherwise, an exception is
- * thrown if a profile cannot be chosen automatically.
- *
- * @throws Exception
- */
- function install_select_profile(&$install_state) {
- if (empty($install_state['parameters']['profile'])) {
-
- $profile = _install_select_profile($install_state['profiles']);
- if (empty($profile)) {
-
-
-
-
-
- if ($install_state['interactive']) {
- include_once BACKDROP_ROOT . '/core/includes/form.inc';
- backdrop_set_title(st('Select an installation profile'));
- $form = backdrop_get_form('install_select_profile_form', $install_state['profiles']);
- return backdrop_render($form);
- }
- else {
- throw new Exception(install_no_profile_error());
- }
- }
- else {
- $install_state['parameters']['profile'] = $profile;
- }
- }
- }
-
- * Selects an installation profile from a list or from a $_POST submission.
- *
- * @return string|NULL
- * The selected profile from $_POST, or the automatically selected profile if
- * possible to determine one without prompting the user. If no profile can
- * be selected, NULL is returned.
- *
- * @throws Exception
- */
- function _install_select_profile($profiles) {
- if (sizeof($profiles) == 0) {
- throw new Exception(install_no_profile_error());
- }
-
- if (sizeof($profiles) == 1) {
- $profile = array_pop($profiles);
- return $profile->name;
- }
- else {
- $available_profiles = array();
- $exclusive_profiles = array();
- foreach ($profiles as $profile) {
- if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) {
- return $profile->name;
- }
-
- $profile_info = install_profile_info($profile->name);
-
- if (empty($profile_info['hidden'])) {
- $available_profiles[] = $profile->name;
- }
-
- if (!empty($profile_info['exclusive'])) {
- $exclusive_profiles[] = $profile->name;
- }
- }
-
-
- if (count($available_profiles) == 1) {
- return reset($available_profiles);
- }
-
- elseif (count($exclusive_profiles) == 1) {
- return reset($exclusive_profiles);
- }
- }
-
-
- return NULL;
- }
-
- * Form constructor for the profile selection form.
- *
- * @param $form_state
- * Array of metadata about state of form processing.
- * @param $profile_files
- * Array of .profile files, as returned from file_scan_directory().
- *
- * @ingroup forms
- */
- function install_select_profile_form($form, &$form_state, $profile_files) {
- $profiles = array();
- $names = array();
-
- foreach ($profile_files as $profile) {
-
- include_once BACKDROP_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' => st($name),
- '#description' => isset($profiles[$profile]['description']) ? st($profiles[$profile]['description']) : '',
- '#parents' => array('profile'),
- );
- }
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => st('Save and continue'),
- );
- return $form;
- }
-
- * Find all .po files useful for the installer.
- */
- function install_find_translations() {
- $files = install_find_translation_files();
-
- array_unshift($files, (object) array('name' => 'en'));
- foreach ($files as $key => $file) {
-
- $files[$key]->langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $file->name);
- }
- return $files;
- }
-
- * Find installer translations either for a specific langcode or all languages.
- *
- * @param $langcode
- * (optional) The language code corresponding to the language for which we
- * want to find translation files. If omitted, information on all available
- * files will be returned.
- *
- * @return
- * An associative array of file information objects keyed by file URIs as
- * returned by file_scan_directory().
- *
- * @see file_scan_directory()
- */
- function install_find_translation_files($langcode = NULL) {
- $directory = settings_get('locale_translate_file_directory', conf_path() . '/files/translations');
-
-
- $files = file_scan_directory($directory, '!(install|drupal|backdrop(cms)?)(-[\d\.x]+)?\.' . (!empty($langcode) ? preg_quote($langcode, '!') : '[^\.]+') . '\.po$!', array('recurse' => FALSE));
-
- return $files;
- }
-
- * Installation task; select which language to use.
- *
- * @param array $install_state
- * An array of information about the current installation state. The chosen
- * langcode will be added here, if it was not already selected previously, as
- * will a list of all available languages.
- *
- * @return string|NULL
- * For interactive installations, a form or other page output allowing the
- * language to be selected or providing information about language selection,
- * if a language has not been chosen. For non-interactive installs, nothing
- * is returned. An exception is thrown if a language cannot be chosen
- * automatically.
- *
- * @throws Exception
- */
- function install_select_language(&$install_state) {
-
- $files = install_find_translations();
- $install_state['translations'] += $files;
- include_once BACKDROP_ROOT . '/core/includes/standard.inc';
-
- $standard_languages = install_get_available_translations($files);
-
- if (!empty($_POST['langcode'])) {
- $langcode = $_POST['langcode'];
- if ($langcode == 'en' || isset($standard_languages[$langcode])) {
- $install_state['parameters']['langcode'] = $langcode;
- return;
- }
- }
-
- if (empty($install_state['parameters']['langcode'])) {
-
-
-
-
- if (count($standard_languages) == 1) {
- if ($install_state['interactive']) {
- $directory = settings_get('locale_translate_file_directory', conf_path() . '/files/translations');
-
- backdrop_set_title(st('Choose language'));
- if (!empty($install_state['parameters']['translate'])) {
- $output = '<p>Follow these steps to translate Backdrop into your language:</p>';
- $output .= '<ol>';
- if (!install_check_localization_server(INSTALL_AVAILABLE_TRANSLATIONS_URI)) {
- $output .= '<li>Ensure that you are connected to the internet, since Backdrop is able to automatically download new translations. Alternatively,</li>';
- }
- $output .= '<li>Download a translation from the <a href="https://localize.backdropcms.org/translate/languages" target="_blank">translation server</a>.</li>';
- $output .= '<li>Place it into the following directory:<pre>' . $directory . '</pre></li>';
- $output .= '</ol>';
- $output .= '<p>For more information on installing Backdrop in different languages, visit the <a href="https://backdropcms.org/installing-in-other-languages" target="_blank">Backdrop user guide page</a>.</p>';
- $output .= '<p>How should the installation continue?</p>';
- $output .= '<ul>';
- $output .= '<li><a href="' . check_url(backdrop_current_script_url(array('translate' => NULL))) . '">Reload the language selection page after adding translations</a></li>';
- $output .= '<li><a href="' . check_url(backdrop_current_script_url(array(
- 'langcode' => 'en',
- 'translate' => NULL,
- ))) . '">Continue installation in English</a></li>';
- $output .= '</ul>';
- }
- else {
- include_once BACKDROP_ROOT . '/core/includes/form.inc';
- $elements = backdrop_get_form('install_select_language_form', $files, $standard_languages);
- $output = backdrop_render($elements);
- }
- return $output;
- }
-
-
- $single_language = reset($standard_languages);
- $install_state['parameters']['langcode'] = key($single_language);
- return NULL;
- }
- else {
-
-
-
-
-
- if ($install_state['interactive']) {
- backdrop_set_title(st('Choose language'));
- include_once BACKDROP_ROOT . '/core/includes/form.inc';
- $elements = backdrop_get_form('install_select_language_form', $files, $standard_languages);
- return backdrop_render($elements);
- }
- else {
- throw new Exception(st('Sorry, you must select a language to continue the installation.'));
- }
- }
- }
-
- else {
- return NULL;
- }
- }
-
- * Form constructor for the language selection form.
- *
- * @ingroup forms
- */
- function install_select_language_form($form, &$form_state, $files, $standard_languages) {
- include_once BACKDROP_ROOT . '/core/includes/standard.inc';
- include_once BACKDROP_ROOT . '/core/includes/locale.inc';
-
- $select_options = array();
- $browser_options = array();
-
- $form['#title'] = st('Choose language');
-
-
-
-
-
- foreach ($standard_languages as $langcode => $language_names) {
- $select_options[$langcode] = isset($language_names[1]) ? $language_names[1] : $language_names[0];
-
- $browser_options[$langcode] = (object) array(
- 'langcode' => $langcode,
- );
- }
- asort($select_options);
-
- $browser_langcode = locale_language_from_browser($browser_options);
- $form['langcode'] = array(
- '#type' => 'select',
- '#options' => $select_options,
-
- '#default_value' => !empty($browser_langcode) ? $browser_langcode : 'en',
- );
-
- if (count($standard_languages) == 1) {
- $form['help'] = array(
- '#type' => 'help',
- '#markup' => '<a href="' . check_url(backdrop_current_script_url(array('translate' => 'true'))) . '">' . st('Learn how to install Backdrop in other languages') . '</a>',
- );
- }
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => st('Save and continue'),
- );
- return $form;
- }
-
- * Provide a list of available translation files.
- *
- * @return array
- * An array of language codes.
- */
- function install_get_available_translations($files) {
- $available_translations = array();
- $response = backdrop_http_request(INSTALL_AVAILABLE_TRANSLATIONS_URI, array(
- 'timeout' => 5,
- ));
- $data = array();
- if ($response->code === '200') {
- $data = json_decode($response->data, TRUE);
- }
-
- if ($data) {
- $available_translations = array_keys($data);
- }
- elseif (count($files) > 1) {
- foreach($files as $translation_file) {
- $available_translations[] = $translation_file->langcode;
- }
- }
-
-
- $available_translations[] = 'en';
- $standard_languages = standard_language_list();
- return array_intersect_key($standard_languages, array_flip(array_unique($available_translations)));
- }
-
- * Download a translation file for the selected language.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return string
- * A themed status report, or an exception if there are requirement errors.
- * Upon successful download the page is reloaded and no output is returned.
- */
- function install_download_translation(array &$install_state) {
-
-
- $requirements = install_check_translation_download($install_state['parameters']['langcode']);
-
- if ($output = install_display_requirements($install_state, $requirements)) {
- return $output;
- }
-
-
- $install_state['translations'][$install_state['parameters']['langcode']] = TRUE;
- }
-
- * Attempts to get a file using a HTTP request and to store it locally.
- *
- * @param string $uri
- * The URI of the file to grab.
- * @param string $destination
- * Stream wrapper URI specifying where the file should be placed. If a
- * directory path is provided, the file is saved into that directory under its
- * original name. If the path contains a filename as well, that one will be
- * used instead.
- *
- * @return bool
- * TRUE on success, FALSE on failure.
- */
- function install_retrieve_file($uri, $destination) {
- $parsed_url = parse_url($uri);
-
- if (is_dir(backdrop_realpath($destination))) {
-
- $path = str_replace('///', '//', "$destination/") . backdrop_basename($parsed_url['path']);
- }
- else {
- $path = $destination;
- }
-
- $response = backdrop_http_request($uri, array('timeout' => 5));
- if ($response->code != 200) {
- return FALSE;
- }
-
- $data = $response->data;
- if (empty($data)) {
- return FALSE;
- }
-
- return file_put_contents($path, $data) !== FALSE;
- }
-
- * Checks if the localization server can be contacted.
- *
- * @param string $uri
- * The URI to contact.
- *
- * @return string
- * TRUE if the URI was contacted successfully, FALSE if not.
- */
- function install_check_localization_server($uri) {
-
- $online = &backdrop_static(__FUNCTION__, TRUE);
- if (!$online) {
- return FALSE;
- }
-
- $options = array(
- 'method' => 'HEAD',
- 'timeout' => 5,
- );
- $response = backdrop_http_request($uri, $options);
- if ($response->code != 200) {
- $online = FALSE;
- return $online;
- }
- return TRUE;
- }
-
- * Checks installation requirements, downloads a translation, and reports any
- * errors.
- *
- * This function is only called if the user selects a translation that is not
- * English and for which there is no local translation file.
- *
- * @param string $langcode
- * Language code to check for download.
- *
- * @return array
- * Requirements compliance array. If the translation cannot be downloaded this
- * will contain a requirements error with detailed information.
- *
- * @see install_state_defaults()
- * @see install_download_translation()
- */
- function install_check_translation_download($langcode) {
- $requirements = array();
-
- $readable = FALSE;
- $writable = FALSE;
- $translation_available = FALSE;
-
- $files_directory = conf_path() . '/files';
- $translations_directory = settings_get('locale_translate_file_directory', conf_path() . '/files/translations');
- $translations_directory_exists = FALSE;
- $online = FALSE;
-
-
- file_prepare_directory($files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
-
-
- file_prepare_directory($translations_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
-
-
- if (backdrop_verify_install_file($translations_directory, FILE_EXIST, 'dir')) {
- $readable = is_readable($translations_directory);
- $writable = is_writable($translations_directory);
- $translations_directory_exists = TRUE;
- }
-
- $version = BACKDROP_VERSION;
- $fallback_version = BACKDROP_CORE_COMPATIBILITY;
-
-
- if (preg_match("/^(\d+)\.(\d+)/", $version, $matches)) {
- $version = $matches[0];
- $fallback_version = $matches[1] . '.x';
- }
-
-
- $variables = array(
- '%project' => 'backdropcms',
- '%version' => $version,
- '%core' => 'all',
- '%language' => $langcode,
- );
- $translation_url = strtr(INSTALL_LOCALIZATION_SERVER_PATTERN, $variables);
-
- $variables['%version'] = $fallback_version;
- $fallback_url = strtr(INSTALL_LOCALIZATION_SERVER_PATTERN, $variables);
-
- $elements = parse_url($translation_url);
- $server_url = $elements['scheme'] . '://' . $elements['host'];
-
-
- include_once BACKDROP_ROOT . '/core/includes/standard.inc';
-
- $languages = standard_language_list();
- $language = isset($languages[$langcode]) ? $languages[$langcode][0] : $langcode;
-
-
-
-
- if (install_check_localization_server($server_url)) {
- $online = TRUE;
- }
- if ($online) {
-
-
- $translation_available = install_check_localization_server($fallback_url);
- if ($translation_available) {
-
-
-
- if (!install_check_localization_server($translation_url)) {
- $translation_url = $fallback_url;
- }
- }
- }
-
-
- if (!$translations_directory_exists) {
- $requirements['translations directory exists'] = array(
- 'title' => st('Translations directory'),
- 'value' => st('The translations directory does not exist.'),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => st('The installation process requires a translations directory to be created under <code>%translations_directory</code>. The <a href="!install_docs">How to install Backdrop CMS</a> documentation page offers help on this and other topics.', array(
- '%translations_directory' => $translations_directory,
- '!install_docs' => 'https://docs.backdropcms.org/documentation/installation-instructions',
- )),
- );
- }
- else {
- $requirements['translations directory exists'] = array(
- 'title' => st('Translations directory'),
- 'value' => st('The directory <code>%translations_directory</code> exists.', array(
- '%translations_directory' => $translations_directory,
- )),
- );
-
- if (!$readable) {
- $requirements['translations directory readable'] = array(
- 'title' => st('Translations directory'),
- 'value' => st('The translations directory is not readable.'),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => st('The installer requires read permissions to <code>%translations_directory</code> at all times. The <a href="!handbook_url">File permissions and ownership</a> documentation section offers help on this and other topics.', array(
- '%translations_directory' => $translations_directory,
- '!handbook_url' => 'https://docs.backdropcms.org/documentation/file-permissions-and-ownership',
- )),
- );
- }
-
- if (!$writable) {
- $requirements['translations directory writable'] = array(
- 'title' => st('Translations directory'),
- 'value' => st('The translations directory is not writable.'),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => st('The installer requires write permissions to the <code>%translations_directory<code> directory during the installation process. The <a href="!handbook_url">File permissions and ownership</a> documentation section offers help on this and other topics.', array(
- '%translations_directory' => $translations_directory,
- '!handbook_url' => 'https://docs.backdropcms.org/documentation/file-permissions-and-ownership',
- )),
- );
- }
- else {
- $requirements['translations directory writable'] = array(
- 'title' => st('Translations directory'),
- 'value' => st('The translations directory is writable.'),
- );
- }
- }
-
-
- if (!$online) {
- $requirements['online'] = array(
- 'title' => st('Internet'),
- 'value' => st('The translation server is offline or cannot be reached.'),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => st('The installer was unable to contact the translation server to download a translation file. Check your internet connection and verify that your website can reach the translation server at <a href="!server_url">@server_url</a> , or <a href="!url">continue in English</a> and translate your website later.', array(
- '!server_url' => $server_url,
- '@server_url' => $server_url,
- '!url' => $_SERVER['SCRIPT_NAME'],
- )),
- );
- }
- else {
- $requirements['online'] = array(
- 'title' => st('Internet'),
- 'value' => st('The translation server is online.'),
- );
-
-
- if (!$translation_available) {
- $requirements['translation available'] = array(
- 'title' => st('Translation'),
- 'value' => st('The %language translation is not available.', array(
- '%language' => $language,
- )),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => st('The %language translation file is not available at the translation server. <a href="!url">Choose a different language</a> or select English and translate your website later.', array(
- '%language' => $language,
- '!url' => $_SERVER['SCRIPT_NAME'],
- )),
- );
- }
- else {
- $requirements['translation available'] = array(
- 'title' => st('Translation'),
- 'value' => st('The %language translation is available.', array(
- '%language' => $language,
- )),
- );
- }
- }
-
- if ($translations_directory_exists && $readable && $writable && $translation_available) {
- $translation_downloaded = install_retrieve_file($translation_url, $translations_directory);
-
- if (!$translation_downloaded) {
- $requirements['translation downloaded'] = array(
- 'title' => st('Translation'),
- 'value' => st('The %language translation could not be downloaded.', array(
- '%language' => $language,
- )),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => st('The %language translation file could not be downloaded. <a href="!url">Choose a different language</a> or select English and translate your website later.', array(
- '%language' => $language,
- '!url' => $_SERVER['SCRIPT_NAME'],
- )),
- );
- }
- }
-
- return $requirements;
- }
-
- * Verifies the requirements for installing Backdrop.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return string|NULL
- * A themed status report, or an exception if there are requirement errors.
- * If there are only requirement warnings, a themed status report is shown
- * initially, but the user is allowed to bypass it by providing 'continue=1'
- * in the URL. Otherwise, no output is returned, so that the next task can be
- * run in the same page request.
- *
- * @throws Exception
- */
- function install_display_requirements($install_state, $requirements) {
-
- $severity = backdrop_requirements_severity($requirements);
-
-
-
-
-
- if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && empty($install_state['parameters']['continue']))) {
- if ($install_state['interactive']) {
- backdrop_set_title(st('Requirements problem'));
- $status_report = st('Resolve the problems and <a href="!url">try again</a>.', array('!url' => check_url(backdrop_requirements_url($severity))));
- $status_report .= '<br><br>';
- $status_report .= theme(
- 'status_report', array(
- 'requirements' => $requirements,
- 'phase' => 'install',
- )
- );
- 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));
- }
- }
- }
-
-
- return NULL;
- }
-
- * Indicates that there are no profiles available.
- */
- function install_no_profile_error() {
- backdrop_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.');
- }
-
- * Indicates that Backdrop has already been installed.
- */
- function install_already_done_error() {
- global $base_url;
-
- backdrop_set_title(st('Backdrop already installed'));
-
- $items = array();
- $items[] = st('To start over, you must empty your existing database.');
-
- $settings_php = st('To install to a different database, edit the <em>settings.php</em> file located in the root folder of this site.');
- if (conf_path() !== '.') {
- $settings_php = st('To install to a different database, edit the <em>settings.php</em> file corresponding to this site within the <em>sites</em> directory.');
- }
- $items[] = $settings_php;
-
- $items[] = st('To upgrade an existing installation, proceed to the <a href="@base-url/core/update.php">update script</a>.', array('@base-url' => $base_url));
- $items[] = st('View your <a href="@base-url">existing site</a>.', array('@base-url' => $base_url));
-
- return theme('item_list', array('items' => $items));
- }
-
- * Loads information about the chosen profile during installation.
- *
- * @param array $install_state
- * An array of information about the current installation state. The loaded
- * profile information will be added here, or an exception will be thrown if
- * the profile cannot be loaded.
- *
- * @throws Exception
- */
- function install_load_profile(&$install_state) {
- $profile_file = _install_find_profile_file($install_state['parameters']['profile']);
- if ($profile_file) {
- include_once $profile_file;
- $install_state['profile_info'] = install_profile_info($install_state['parameters']['profile'], $install_state['parameters']['langcode']);
- }
- else {
- throw new Exception(st('Sorry, the profile you have chosen cannot be loaded.'));
- }
- }
-
- * Performs a full bootstrap of Backdrop during installation.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- */
- function install_bootstrap_full(&$install_state) {
- backdrop_bootstrap(BACKDROP_BOOTSTRAP_FULL);
- }
-
- * Installs required modules via a batch process.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * The batch definition.
- */
- function install_profile_modules(&$install_state) {
- $modules = state_get('install_profile_modules', array());
- $files = system_rebuild_module_data();
- state_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 @profile', array('@profile' => backdrop_install_profile_distribution_name())),
- 'error_message' => st('The installation has encountered an error.'),
- 'finished' => '_install_profile_modules_finished',
- );
- return $batch;
- }
-
- * Imports languages via a batch process during installation.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return array|NULL
- * The batch definition, if there are language files to import.
- */
- function install_import_translations(&$install_state) {
- include_once BACKDROP_ROOT . '/core/includes/locale.inc';
- include_once backdrop_get_path('module', 'locale') . '/locale.bulk.inc';
- $langcode = $install_state['parameters']['langcode'];
-
- include_once BACKDROP_ROOT . '/core/includes/standard.inc';
- module_enable(array('language', 'locale'));
- $standard_languages = standard_language_list();
- if (!isset($standard_languages[$langcode])) {
-
-
- $language = (object) array(
- 'langcode' => $langcode,
- 'name' => $langcode,
- 'native' => $langcode,
- 'default' => TRUE,
- );
- language_save($language);
- }
- else {
-
- $language = (object) array(
- 'langcode' => $langcode,
- 'default' => TRUE,
- );
- language_save($language);
- }
-
-
- $batch = locale_translate_batch_import_files($langcode);
- if (!empty($batch)) {
- return $batch;
- }
-
-
- return NULL;
- }
-
- * Form constructor for a form to configure the new site.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @see install_configure_form_validate()
- * @see install_configure_form_submit()
- * @ingroup forms
- */
- function install_configure_form($form, &$form_state, &$install_state) {
- backdrop_set_title(st('Configure site'));
-
- backdrop_add_js(backdrop_get_path('module', 'system') . '/js/system.admin.js');
-
- backdrop_add_js('core/misc/timezone.js');
-
-
- backdrop_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting');
- backdrop_add_js('jQuery(function () { Backdrop.cleanURLsInstallCheck(); });', 'inline');
-
- menu_rebuild();
-
-
-
-
-
-
-
-
-
- backdrop_get_schema(NULL, TRUE);
-
-
- return _install_configure_form($form, $form_state, $install_state);
- }
-
- * Installation task; finish importing files at end of installation.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * The batch definition, if there are language files to import.
- *
- * @todo
- * This currently does the same as the first import step. Need to revisit
- * once we have l10n_update functionality integrated. See
- * http://drupal.org/node/1191488.
- */
- function install_import_translations_remaining(&$install_state) {
- include_once backdrop_get_path('module', 'locale') . '/locale.bulk.inc';
- return locale_translate_batch_import_files($install_state['parameters']['langcode']);
- }
-
- * Finishes importing files at end of installation.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @return
- * A message informing the user that the installation is complete.
- */
- function install_finished(&$install_state) {
-
-
-
- backdrop_flush_all_caches();
-
-
- config_set('system.core', 'install_profile', $install_state['parameters']['profile']);
-
-
- db_update('system')
- ->fields(array('weight' => 1000))
- ->condition('type', 'module')
- ->condition('name', $install_state['parameters']['profile'])
- ->execute();
-
-
- backdrop_get_schema(NULL, TRUE);
-
-
-
- state_set('install_task', 'done');
-
-
- $connection = Database::getConnection();
- if ($connection->utf8mb4IsActive()) {
- state_set('database_utf8mb4_active', TRUE);
- }
-
-
-
-
- backdrop_cron_run();
-
- $profile = backdrop_install_profile_distribution_name();
- $message = st('Thank you for installing @profile!', array('@profile' => $profile));
-
-
- if (module_exists('dashboard')) {
- $message .= '<br>' . st('If you are new to @profile, then the <a href="@dashboard">Dashboard</a> may be a good place to start.', array('@profile' => $profile, '@dashboard' => url('admin/dashboard')));
- }
-
- if (!backdrop_is_cli()) {
- backdrop_set_message($message);
- backdrop_goto('<front>');
- }
- }
-
- * Batch callback for batch installation of modules.
- */
- 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));
- }
-
- * 'Finished' callback for module installation batch.
- */
- function _install_profile_modules_finished($success, $results, $operations) {
-
-
- backdrop_flush_all_caches();
- }
-
- * Checks installation requirements and reports any errors.
- */
- function install_check_requirements($install_state) {
- $profile = $install_state['parameters']['profile'];
-
- $requirements = array();
-
-
- if (!$install_state['settings_verified']) {
- $writable = FALSE;
- $conf_path = conf_path(FALSE, TRUE);
- $settings_file = $conf_path . '/settings.php';
- $exists = FALSE;
-
- if (backdrop_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
-
- if (backdrop_verify_install_file($settings_file, FILE_EXIST)) {
-
- $writable = backdrop_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
- $exists = TRUE;
- }
- elseif ($settings_file !== './settings.php') {
- if (copy('./settings.php', $settings_file) === TRUE) {
- $exists = TRUE;
- $writable = backdrop_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 @profile installer could not find a settings.php file. Please place copy of this file into @file.', array('@profile' => backdrop_install_profile_distribution_name(), '@file' => $settings_file)),
- );
- return $requirements;
- }
- else {
- $requirements['settings file exists'] = array(
- 'title' => st('Settings file'),
- 'value' => st('The %file file exists.', array('%file' => $settings_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 @profile 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">Installation Instructions</a> page.', array('@profile' => backdrop_install_profile_distribution_name(), '%file' => $settings_file, '@handbook_url' => 'https://backdropcms.org/installation')),
- );
- }
- else {
- $requirements['settings file'] = array(
- 'title' => st('Settings file'),
- 'value' => st('The settings file is writable.'),
- );
- }
- }
-
-
- $requirements += backdrop_check_profile($profile);
-
- return $requirements;
- }
-
- * Form constructor for a site configuration form.
- *
- * @param array $install_state
- * An array of information about the current installation state.
- *
- * @see install_configure_form()
- * @see install_configure_form_validate()
- * @see install_configure_form_submit()
- * @ingroup forms
- */
- function _install_configure_form($form, &$form_state, &$install_state) {
- include_once BACKDROP_ROOT . '/core/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['admin_account'] = array(
- '#type' => 'fieldset',
- '#title' => st('Primary user 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, pluses, hyphens, and underscores.'),
- '#required' => TRUE,
- '#weight' => -10,
- '#attributes' => array('class' => array('username')),
- );
-
- $form['admin_account']['account']['mail'] = array(
- '#type' => 'email',
- '#title' => st('Email address'),
- '#required' => TRUE,
- '#weight' => -5,
- );
- $form['admin_account']['account']['pass'] = array(
- '#title' => st('Password'),
- '#type' => 'password',
- '#required' => TRUE,
- '#weight' => 0,
- '#password_toggle' => TRUE,
- '#password_strength' => TRUE,
- );
-
- $form['server_settings'] = array(
- '#type' => 'fieldset',
- '#title' => st('Server settings'),
- '#collapsible' => FALSE,
- );
-
- $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 email 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="https://backdropcms.org">BackdropCMS.org</a>.'),
- '#weight' => 15,
- );
- $form['update_notifications']['update_status_module'][2] = array(
- '#states' => array(
- 'visible' => array(
- 'input[name="update_status_module[1]"]' => array('checked' => TRUE),
- ),
- ),
- );
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => st('Save and continue'),
- '#weight' => 15,
- );
-
- return $form;
- }
-
- * Form validation handler for install_configure_form().
- *
- * @see install_configure_form_submit()
- */
- 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);
- }
- }
-
- * Form submission handler for install_configure_form().
- *
- * @see install_configure_form_validate()
- */
- function install_configure_form_submit($form, &$form_state) {
- global $user;
- $timezone = $form_state['values']['date_default_timezone'];
- $timezone_country = _install_get_timezone_country($timezone);
-
- config('system.core')
- ->set('site_name', $form_state['values']['site_name'])
- ->save();
- config('system.date')
- ->set('default_timezone', $timezone)
- ->set('default_country', $timezone_country)
- ->save();
-
-
- if ($timezone_country == 'US') {
- config('system.date')
- ->set('formats.long.pattern', 'l, F j, Y - g:ia')
- ->set('formats.medium.pattern', 'D, m/d/Y - g:ia')
- ->set('formats.short.pattern', 'm/d/Y - g:ia')
- ->set('formats.date_only.pattern', 'm/d/Y')
- ->save();
- }
-
-
- if (module_exists('update')) {
-
- config_set('update.settings', 'update_interval_days', (int) $form_state['values']['update_status_module'][1]);
-
-
-
- if ($form_state['values']['update_status_module'][2]) {
- config_set('update.settings', 'update_emails', array($form_state['values']['account']['mail']));
- }
- }
-
-
- $account = user_load(1);
- $account->init = $account->mail = $form_state['values']['account']['mail'];
- $account->roles = !empty($account->roles) ? $account->roles : array();
- $account->status = 1;
- $account->timezone = $timezone;
- $account->pass = $form_state['values']['account']['pass'];
- $account->name = $form_state['values']['account']['name'];
- $account->save();
-
- $user = user_load(1);
- user_login_finalize();
-
- if (isset($form_state['values']['clean_url'])) {
- config_set('system.core', 'clean_url', $form_state['values']['clean_url']);
- backdrop_static_reset('url');
- }
-
-
- state_set('install_time', $_SERVER['REQUEST_TIME']);
- }
-
- * Get a country code for the provided timezone.
- */
- function _install_get_timezone_country($timezone) {
-
- include_once BACKDROP_ROOT . '/core/includes/locale.inc';
- $timezone_countries = timezone_country_get_list();
-
-
- $timezone = str_replace(' ', '_', $timezone);
-
-
- if (isset($timezone_countries[$timezone])) {
- return $timezone_countries[$timezone];
- }
- else {
- return '';
- }
- }