Commit 53d757cb authored by webchick's avatar webchick
Browse files

Issue #2084339 by alexpott: Fixed The configuration value...

Issue #2084339 by alexpott: Fixed The configuration value system.maintenance.enabled should be moved to the state system.
parent 63603999
......@@ -3418,7 +3418,7 @@ function _menu_router_save($menu, $masks) {
*/
function _menu_site_is_offline($check_only = FALSE) {
// Check if site is in maintenance mode.
if (Drupal::config('system.maintenance')->get('enabled')) {
if (Drupal::state()->get('system.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
......
......@@ -880,11 +880,8 @@ function update_batch($start, $redirect = NULL, $url = NULL, $batch = array(), $
$_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')) {
Drupal::config('system.maintenance')->set('enabled', TRUE)->save();
if (db_table_exists('state')) {
Drupal::state()->set('system.maintenance_mode', TRUE);
}
}
......@@ -956,9 +953,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'])) {
$GLOBALS['conf']['system.maintenance']['enabled'] = FALSE;
// At this point, the configuration system should exist.
Drupal::config('system.maintenance')->set('enabled', FALSE)->save();
Drupal::state()->set('system.maintenance_mode', FALSE);
unset($_SESSION['maintenance_mode']);
}
}
......
......@@ -83,10 +83,6 @@ function testSchemaMapping() {
$expected = array();
$expected['label'] = 'Maintenance mode';
$expected['class'] = '\Drupal\Core\Config\Schema\Mapping';
$expected['mapping']['enabled'] = array(
'label' => 'Put site into maintenance mode',
'type' => 'boolean'
);
$expected['mapping']['message'] = array(
'label' => 'Message to display when in maintenance mode',
'type' => 'text',
......
......@@ -40,9 +40,6 @@ system.maintenance:
type: mapping
label: 'Maintenance mode'
mapping:
enabled:
type: boolean
label: 'Put site into maintenance mode'
message:
type: text
label: 'Message to display when in maintenance mode'
......
......@@ -32,7 +32,7 @@ public function access(Route $route, Request $request) {
watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE);
return static::KILL;
}
elseif (\Drupal::config('system.maintenance')->get('enabled')) {
elseif (\Drupal::state()->get('system.maintenance_mode')) {
watchdog('cron', 'Cron could not run because the site is in maintenance mode.', array(), WATCHDOG_NOTICE);
return static::KILL;
}
......
......@@ -7,13 +7,50 @@
namespace Drupal\system\Form;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Config\Context\ContextInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\system\SystemConfigFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure maintenance settings for this site.
*/
class SiteMaintenanceModeForm extends SystemConfigFormBase {
/**
* The state keyvalue collection.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
protected $state;
/**
* Constructs a \Drupal\system\SystemConfigFormBase object.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Config\Context\ContextInterface $context
* The configuration context to use.
* @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state
* The state keyvalue collection to use.
*/
public function __construct(ConfigFactory $config_factory, ContextInterface $context, KeyValueStoreInterface $state) {
parent::__construct($config_factory, $context);
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('config.context.free'),
$container->get('state')
);
}
/**
* {@inheritdoc}
*/
......@@ -29,7 +66,7 @@ public function buildForm(array $form, array &$form_state) {
$form['maintenance_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Put site into maintenance mode'),
'#default_value' => $config->get('enabled'),
'#default_value' => $this->state->get('system.maintenance_mode'),
'#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(
......@@ -46,10 +83,10 @@ public function buildForm(array $form, array &$form_state) {
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.maintenance')
->set('enabled', $form_state['values']['maintenance_mode'])
->set('message', $form_state['values']['maintenance_mode_message'])
->save();
$this->state->set('system.maintenance_mode', $form_state['values']['maintenance_mode']);
parent::submitForm($form, $form_state);
}
......
......@@ -151,7 +151,7 @@ function testExoticPath() {
* Test the theme callback when the site is in maintenance mode.
*/
function testThemeCallbackMaintenanceMode() {
\Drupal::config('system.maintenance')->set('enabled', 1)->save();
$this->container->get('state')->set('system.maintenance_mode', TRUE);
theme_enable(array($this->admin_theme));
// For a regular user, the fact that the site is in maintenance mode means
......@@ -166,7 +166,7 @@ function testThemeCallbackMaintenanceMode() {
$this->assertText('Custom theme: seven. Actual theme: seven.', 'The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.');
$this->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");
\Drupal::config('system.maintenance')->set('enabled', 0)->save();
$this->container->get('state')->set('system.maintenance_mode', FALSE);
}
/**
......@@ -175,7 +175,7 @@ function testThemeCallbackMaintenanceMode() {
* @see \Drupal\menu_test\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance().
*/
function testMaintenanceModeLoginPaths() {
\Drupal::config('system.maintenance')->set('enabled', 1)->save();
$this->container->get('state')->set('system.maintenance_mode', TRUE);
$offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => \Drupal::config('system.site')->get('name')));
$this->drupalGet('test-page');
......@@ -183,7 +183,7 @@ function testMaintenanceModeLoginPaths() {
$this->drupalGet('menu_login_callback');
$this->assertText('This is TestControllers::testLogin.', 'Maintenance mode can be bypassed using an event subscriber.');
\Drupal::config('system.maintenance')->set('enabled', 0)->save();
$this->container->get('state')->set('system.maintenance_mode', FALSE);
}
/**
......
......@@ -45,7 +45,6 @@ public function testVariableUpgrade() {
);
$expected_config['system.maintenance'] = array(
'enabled' => '1',
'message' => 'Testing config upgrade',
);
......
......@@ -1480,9 +1480,11 @@ function system_update_8015() {
*/
function system_update_8016() {
update_variables_to_config('system.maintenance', array(
'maintenance_mode' => 'enabled',
'maintenance_mode_message' => 'message',
));
update_variables_to_state(array(
'maintenance_mode' => 'system.maintenance_mode',
));
}
/**
......
......@@ -191,7 +191,7 @@ function update_authorize_update_batch_finished($success, $results) {
$success = FALSE;
}
}
$offline = Drupal::config('system.maintenance')->get('enabled');
$offline = Drupal::state()->get('system.maintenance_mode');
if ($success) {
// Now that the update completed, we need to clear the available update data
// and recompute our status, so prevent show bogus results.
......@@ -199,7 +199,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) {
Drupal::config('system.maintenance')->set('enabled', FALSE)->save();
Drupal::state()->set('system.maintenance_mode', FALSE);
$page_message = array(
'message' => t('Update was completed successfully. Your site has been taken out of maintenance mode.'),
'type' => 'status',
......@@ -258,11 +258,11 @@ function update_authorize_install_batch_finished($success, $results) {
$success = FALSE;
}
}
$offline = Drupal::config('system.maintenance')->get('enabled');
$offline = Drupal::state()->get('system.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) {
Drupal::config('system.maintenance')->set('enabled', FALSE)->save();
Drupal::state()->set('system.maintenance_mode', FALSE);
$page_message = array(
'message' => t('Installation was completed successfully. Your site has been taken out of maintenance mode.'),
'type' => 'status',
......
......@@ -435,9 +435,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'] = Drupal::config('system.maintenance')->get('enabled');
$_SESSION['maintenance_mode'] = Drupal::state()->get('system.maintenance_mode');
if ($form_state['values']['maintenance_mode'] == TRUE) {
Drupal::config('system.maintenance')->set('enabled', TRUE)->save();
Drupal::state()->set('system.maintenance_mode', TRUE);
}
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