diff --git a/core/cron.php b/core/cron.php index fa9aa14..126d991 100644 --- a/core/cron.php +++ b/core/cron.php @@ -20,7 +20,7 @@ if (!isset($_GET['cron_key']) || variable_get('cron_key', 'drupal') != $_GET['cr watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE); drupal_access_denied(); } -elseif (variable_get('maintenance_mode', 0)) { +elseif (config('system.maintenance')->get('maintenance_mode')) { watchdog('cron', 'Cron could not run because the site is in maintenance mode.', array(), WATCHDOG_NOTICE); drupal_access_denied(); } diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index 8817356..dcfa055 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -515,8 +515,7 @@ function ajax_prepare_response($page_callback_result) { break; case MENU_SITE_OFFLINE: - $commands[] = ajax_command_alert(filter_xss_admin(variable_get('maintenance_mode_message', - t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))))); + $commands[] = ajax_command_alert(filter_xss_admin(t(config('system.maintenance')->get('maintenance_mode_message'), array('@site' => variable_get('site_name', 'Drupal'))))); break; } } diff --git a/core/includes/common.inc b/core/includes/common.inc index a18e1e4..9a2963e 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2592,8 +2592,7 @@ function drupal_deliver_html_page($page_callback_result) { drupal_maintenance_theme(); drupal_add_http_header('Status', '503 Service unavailable'); drupal_set_title(t('Site under maintenance')); - print theme('maintenance_page', array('content' => filter_xss_admin(variable_get('maintenance_mode_message', - t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal'))))))); + print theme('maintenance_page', array('content' => filter_xss_admin(t(config('system.maintenance')->get('maintenance_mode_message'), array('@site' => variable_get('site_name', 'Drupal')))))); break; } } diff --git a/core/includes/config.inc b/core/includes/config.inc index 8c2772b..a137988 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -18,6 +18,9 @@ function config_get_config_directory() { if ($test_prefix = drupal_valid_test_ua()) { $path = conf_path() . '/files/simpletest/config_' . $test_prefix; + file_prepare_directory($path, FILE_CREATE_DIRECTORY); } else { $path = conf_path() . '/files/' . $config_directory_name; diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 511c5d0..4b3d840 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -3795,7 +3795,7 @@ function _menu_router_save($menu, $masks) { */ function _menu_site_is_offline($check_only = FALSE) { // Check if site is in maintenance mode. - if (variable_get('maintenance_mode', 0)) { + if (config('system.maintenance')->get('maintenance_mode')) { if (user_access('access site in maintenance mode')) { // Ensure that the maintenance mode message is displayed only once // (allowing for page redirects) and specifically suppress its display on diff --git a/core/includes/update.inc b/core/includes/update.inc index 1660d7d..ab86ff5 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -107,6 +107,8 @@ function update_prepare_d8_bootstrap() { // Update the dynamic include paths that might be used before running the // proper update functions. update_prepare_stored_includes(); + // Update the environment for the new configuration system. + update_prepare_d8_configuration(); // Update the environment for the language bootstrap if needed. update_prepare_d8_language(); @@ -150,6 +152,18 @@ function update_prepare_stored_includes() { } /** + * Prepare Drupal 8 for configuration system. + */ +function update_prepare_d8_configuration() { + if (!db_table_exists('config')) { + module_load_include('install', 'system'); + $system_schema = system_schema(); + db_create_table('config', $system_schema['config']); + update_variables_to_config('system.maintenance'); + } +} + +/** * Prepare Drupal 8 language changes for the bootstrap if needed. */ function update_prepare_d8_language() { @@ -409,9 +423,9 @@ class DrupalUpdateException extends Exception { } function update_batch($start, $redirect = NULL, $url = NULL, $batch = array(), $redirect_callback = 'drupal_goto') { // During the update, bring the site offline so that schema changes do not // affect visiting users. - $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE); + $_SESSION['maintenance_mode'] = config('system.maintenance')->get('maintenance_mode'); if ($_SESSION['maintenance_mode'] == FALSE) { - variable_set('maintenance_mode', TRUE); + config('system.maintenance')->set('maintenance_mode', TRUE)->save(); } // Resolve any update dependencies to determine the actual updates that will @@ -482,7 +496,7 @@ function update_finished($success, $results, $operations) { // Now that the update is done, we can put the site back online if it was // previously in maintenance mode. if (isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) { - variable_set('maintenance_mode', FALSE); + config('system.maintenance')->set('maintenance_mode', FALSE)->save(); unset($_SESSION['maintenance_mode']); } } @@ -851,7 +865,7 @@ function update_retrieve_dependencies() { /** * Updates config with values set on Drupal 7.x - * + * * Provide a generalised method to migrate variables from Drupal 7 to Drupal 8's * configuration management system. * @@ -863,8 +877,8 @@ function update_retrieve_dependencies() { * An array to map new to old configuration naming conventions. Example: * @code * array('new_config' => 'old_config') - * @endcode - * This would update the value for new_config to the value old_config has in + * @endcode + * This would update the value for new_config to the value old_config has in * the variable table. */ function update_variables_to_config($config_name, $variable_map = array()) { diff --git a/core/modules/openid/openid.test b/core/modules/openid/openid.test index 7a4c9cf..be5581c 100644 --- a/core/modules/openid/openid.test +++ b/core/modules/openid/openid.test @@ -247,7 +247,7 @@ class OpenIDFunctionalTestCase extends OpenIDWebTestCase { $this->drupalLogout(); // Enable maintenance mode. - variable_set('maintenance_mode', 1); + config('system.maintenance')->set('maintenance_mode', TRUE)->save(); // Test logging in via the user/login page while the site is offline. $edit = array('openid_identifier' => $identity); diff --git a/core/modules/simpletest/tests/menu.test b/core/modules/simpletest/tests/menu.test index 8d1d651..e088dd0 100644 --- a/core/modules/simpletest/tests/menu.test +++ b/core/modules/simpletest/tests/menu.test @@ -221,7 +221,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { * Test the theme callback when the site is in maintenance mode. */ function testThemeCallbackMaintenanceMode() { - variable_set('maintenance_mode', TRUE); + config('system.maintenance')->set('maintenance_mode', TRUE)->save(); // For a regular user, the fact that the site is in maintenance mode means // we expect the theme callback system to be bypassed entirely. @@ -242,7 +242,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { * @see hook_menu_site_status_alter(). */ function testMaintenanceModeLoginPaths() { - variable_set('maintenance_mode', TRUE); + config('system.maintenance')->set('maintenance_mode', TRUE)->save(); $offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal'))); $this->drupalLogout(); diff --git a/core/modules/system/config/system.maintenance.xml b/core/modules/system/config/system.maintenance.xml new file mode 100644 index 0000000..f8bf0ad --- /dev/null +++ b/core/modules/system/config/system.maintenance.xml @@ -0,0 +1,5 @@ + + + 0 + @site is currently under maintenance. We should be back shortly. Thank you for your patience. + diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 978b0f4..d4483a0 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -2191,19 +2191,36 @@ function system_date_time_lookup() { * @see system_settings_form() */ function system_site_maintenance_mode() { + $config = config('system.maintenance'); + $form['maintenance_mode'] = array( '#type' => 'checkbox', '#title' => t('Put site into maintenance mode'), - '#default_value' => variable_get('maintenance_mode', 0), + '#default_value' => $config->get('maintenance_mode'), '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" permission will be able to access the site. Authorized users can log in directly via the user login page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))), ); - $form['maintenance_mode_message'] = array( + $form['maintenance_mode_message'] = array( '#type' => 'textarea', '#title' => t('Message to display when in maintenance mode'), - '#default_value' => variable_get('maintenance_mode_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))), + '#default_value' => t($config->get('maintenance_mode_message'), array('@site' => variable_get('site_name', 'Drupal'))), ); - return system_settings_form($form); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); + return $form; +} + +/** + * Form builder submit handler. Handle submission for site maintenance settings. + * + * @ingroup forms + * @see system_settings_form() + */ +function system_site_maintenance_mode_submit($form, &$form_state) { + $config = config('system.maintenance'); + $config->set('maintenance_mode', $form_state['values']['maintenance_mode']); + $config->set('maintenance_mode_message', $form_state['values']['maintenance_mode_message']); + $config->save(); + drupal_set_message(t('The configuration has been saved.')); } /** diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 905d11d..04a9167 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1691,41 +1691,11 @@ function system_update_8002() { } /** - * Adds {config} table for new Configuration system. - */ -function system_update_8003() { - // @todo Temporary. - if (db_table_exists('config')) { - db_drop_table('config'); - } - db_create_table('config', array( - 'description' => 'Default active store for the configuration system.', - 'fields' => array( - 'name' => array( - 'description' => 'The identifier for the configuration entry, such as module.example (the name of the file, minus the file extension).', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'data' => array( - 'description' => 'The raw data for this configuration entry.', - 'type' => 'blob', - 'not null' => TRUE, - 'size' => 'big', - 'translatable' => TRUE, - ), - ), - 'primary key' => array('name'), - )); -} - -/** * Adds {file_managed}.langcode field. * * @see http://drupal.org/node/1454538 */ -function system_update_8004() { +function system_update_8003() { $langcode_field = array( 'description' => 'The {language}.langcode of this file.', 'type' => 'varchar', @@ -1757,7 +1727,7 @@ function system_update_8004() { /** * Remove the obsolete {session}.cache column. */ -function system_update_8005() { +function system_update_8004() { db_drop_field('session', 'cache'); } diff --git a/core/modules/update/update.authorize.inc b/core/modules/update/update.authorize.inc index 48dfd35..939f415 100644 --- a/core/modules/update/update.authorize.inc +++ b/core/modules/update/update.authorize.inc @@ -180,7 +180,7 @@ function update_authorize_update_batch_finished($success, $results) { $success = FALSE; } } - $offline = variable_get('maintenance_mode', FALSE); + $offline = config('system.maintenance')->get('maintenance_mode'); if ($success) { // Now that the update completed, we need to clear the cache of available // update data and recompute our status, so prevent show bogus results. @@ -188,7 +188,7 @@ function update_authorize_update_batch_finished($success, $results) { // Take the site out of maintenance mode if it was previously that way. if ($offline && isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) { - variable_set('maintenance_mode', FALSE); + config('system.maintenance')->set('maintenance_mode', FALSE)->save(); $page_message = array( 'message' => t('Update was completed successfully. Your site has been taken out of maintenance mode.'), 'type' => 'status', @@ -242,11 +242,11 @@ function update_authorize_install_batch_finished($success, $results) { $success = FALSE; } } - $offline = variable_get('maintenance_mode', FALSE); + $offline = config('system.maintenance')->get('maintenance_mode'); if ($success) { // Take the site out of maintenance mode if it was previously that way. if ($offline && isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) { - variable_set('maintenance_mode', FALSE); + config('system.maintenance')->set('maintenance_mode', FALSE)->save(); $page_message = array( 'message' => t('Installation was completed successfully. Your site has been taken out of maintenance mode.'), 'type' => 'status', diff --git a/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc index 82b48f3..3644e24 100644 --- a/core/modules/update/update.manager.inc +++ b/core/modules/update/update.manager.inc @@ -406,9 +406,9 @@ function update_manager_update_ready_form($form, &$form_state) { */ function update_manager_update_ready_form_submit($form, &$form_state) { // Store maintenance_mode setting so we can restore it when done. - $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE); + $_SESSION['maintenance_mode'] = config('system.maintenance')->get('maintenance_mode'); if ($form_state['values']['maintenance_mode'] == TRUE) { - variable_set('maintenance_mode', TRUE); + config('system.maintenance')->set('maintenance_mode', TRUE)->save(); } if (!empty($_SESSION['update_manager_update_projects'])) {