Commit cd224643 authored by webchick's avatar webchick

Issue #1496458 by swentel, pcambra, n3or, kbasarab, sun, marcingy: Convert...

Issue #1496458 by swentel, pcambra, n3or, kbasarab, sun, marcingy: Convert maintenance mode settings to configuration system.
parent 2eb5d3e3
......@@ -447,8 +447,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' => config('system.site')->get('name'))))));
$commands[] = ajax_command_alert(filter_xss_admin(t(config('system.maintenance')->get('message'), array('@site' => config('system.site')->get('name')))));
break;
}
}
......
......@@ -3781,7 +3781,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('enabled')) {
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
......
......@@ -505,9 +505,17 @@ function update_do_one($module, $number, $dependency_map, &$context) {
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);
if ($_SESSION['maintenance_mode'] == FALSE) {
variable_set('maintenance_mode', TRUE);
$maintenance_mode = config('system.maintenance')->get('enabled');
if (isset($maintenance_mode)) {
$_SESSION['maintenance_mode'] = $maintenance_mode;
}
if (empty($_SESSION['maintenance_mode'])) {
$GLOBALS['conf']['system.maintenance']['enabled'] = TRUE;
// @todo This is borderline state, not config. Or a global system
// "maintenance lock".
if (db_table_exists('config')) {
config('system.maintenance')->set('enabled', TRUE)->save();
}
}
// Resolve any update dependencies to determine the actual updates that will
......@@ -577,8 +585,10 @@ 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);
if (isset($_SESSION['maintenance_mode'])) {
$GLOBALS['conf']['system.maintenance']['enabled'] = FALSE;
// At this point, the configuration system should exist.
config('system.maintenance')->set('enabled', FALSE)->save();
unset($_SESSION['maintenance_mode']);
}
}
......
......@@ -39,7 +39,7 @@ public function onKernelRequestMaintenanceModeCheck(GetResponseEvent $event) {
// Deliver the 503 page.
drupal_maintenance_theme();
drupal_set_title(t('Site under maintenance'));
$content = 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' => config('system.site')->get('name')))))));
$content = theme('maintenance_page', array('content' => filter_xss_admin(t(config('system.maintenance')->get('message'), array('@site' => config('system.site')->get('name'))))));
$response = new Response('Service unavailable', 503);
$response->setContent($content);
$event->setResponse($response);
......
......@@ -189,7 +189,7 @@ function testLoginMaintenanceMode() {
$this->drupalLogout();
// Enable maintenance mode.
variable_set('maintenance_mode', 1);
config('system.maintenance')->set('enabled', TRUE)->save();
// Test logging in via the user/login page while the site is offline.
$edit = array('openid_identifier' => $identity);
......
enabled: '0'
message: @site is currently under maintenance. We should be back shortly. Thank you for your patience.
......@@ -123,7 +123,7 @@ function testExoticPath() {
* Test the theme callback when the site is in maintenance mode.
*/
function testThemeCallbackMaintenanceMode() {
variable_set('maintenance_mode', TRUE);
config('system.maintenance')->set('enabled', 1)->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.
......@@ -136,6 +136,8 @@ function testThemeCallbackMaintenanceMode() {
$this->drupalGet('menu-test/theme-callback/use-admin-theme');
$this->assertText('Custom theme: seven. Actual theme: seven.', t('The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.'));
$this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page."));
config('system.maintenance')->set('enabled', 0)->save();
}
/**
......@@ -144,13 +146,15 @@ function testThemeCallbackMaintenanceMode() {
* @see hook_menu_site_status_alter().
*/
function testMaintenanceModeLoginPaths() {
variable_set('maintenance_mode', TRUE);
config('system.maintenance')->set('enabled', 1)->save();
$offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => config('system.site')->get('name')));
$this->drupalGet('node');
$this->assertText($offline_message);
$this->drupalGet('menu_login_callback');
$this->assertText('This is menu_login_callback().', t('Maintenance mode can be bypassed through hook_menu_site_status_alter().'));
config('system.maintenance')->set('enabled', 0)->save();
}
/**
......
......@@ -2222,22 +2222,35 @@ function system_date_time_lookup() {
* Form builder; Configure the site's maintenance status.
*
* @ingroup forms
* @see system_settings_form()
* @see system_site_maintenance_mode_submit()
*/
function system_site_maintenance_mode() {
function system_site_maintenance_mode($form, &$form_state) {
$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('enabled'),
'#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" <a href="@permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))),
);
$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' => config('system.site')->get('name')))),
'#default_value' => $config->get('message'),
);
return system_settings_form($form);
return system_config_form($form, $form_state);
}
/**
* Form submission handler for system_site_maintenance_mode().
*
* @ingroup forms
*/
function system_site_maintenance_mode_submit($form, &$form_state) {
config('system.maintenance')
->set('enabled', $form_state['values']['maintenance_mode'])
->set('message', $form_state['values']['maintenance_mode_message'])
->save();
}
/**
......
......@@ -1181,7 +1181,7 @@ function system_cron_access($key) {
watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE);
return FALSE;
}
elseif (variable_get('maintenance_mode', 0)) {
elseif (config('system.maintenance')->get('enabled')) {
watchdog('cron', 'Cron could not run because the site is in maintenance mode.', array(), WATCHDOG_NOTICE);
return FALSE;
}
......
......@@ -190,7 +190,7 @@ function update_authorize_update_batch_finished($success, $results) {
$success = FALSE;
}
}
$offline = variable_get('maintenance_mode', FALSE);
$offline = config('system.maintenance')->get('enabled');
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.
......@@ -198,7 +198,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('enabled', FALSE)->save();
$page_message = array(
'message' => t('Update was completed successfully. Your site has been taken out of maintenance mode.'),
'type' => 'status',
......@@ -257,11 +257,11 @@ function update_authorize_install_batch_finished($success, $results) {
$success = FALSE;
}
}
$offline = variable_get('maintenance_mode', FALSE);
$offline = config('system.maintenance')->get('enabled');
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('enabled', FALSE)->save();
$page_message = array(
'message' => t('Installation was completed successfully. Your site has been taken out of maintenance mode.'),
'type' => 'status',
......
......@@ -423,9 +423,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('enabled');
if ($form_state['values']['maintenance_mode'] == TRUE) {
variable_set('maintenance_mode', TRUE);
config('system.maintenance')->set('enabled', TRUE)->save();
}
if (!empty($_SESSION['update_manager_update_projects'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment