diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 0b59cfe..af42875 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -3417,7 +3417,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 diff --git a/core/includes/update.inc b/core/includes/update.inc index 4bd4e16..0808cfc 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -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']); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index e1ea9b7..2a36208 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -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', diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index 46143fd..6572ee8 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -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' diff --git a/core/modules/system/lib/Drupal/system/Access/CronAccessCheck.php b/core/modules/system/lib/Drupal/system/Access/CronAccessCheck.php index 05a131d..ccff863 100644 --- a/core/modules/system/lib/Drupal/system/Access/CronAccessCheck.php +++ b/core/modules/system/lib/Drupal/system/Access/CronAccessCheck.php @@ -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; } diff --git a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php index a196cda..e83b93f 100644 --- a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php +++ b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php @@ -7,7 +7,12 @@ 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. @@ -15,6 +20,38 @@ 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} */ public function getFormID() { @@ -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" 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( @@ -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); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php index 31ef055..38cbba9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php @@ -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); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php index 4b22f93..6b0ad23 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php @@ -45,7 +45,6 @@ public function testVariableUpgrade() { ); $expected_config['system.maintenance'] = array( - 'enabled' => '1', 'message' => 'Testing config upgrade', ); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 447320c..5222f25 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -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', + )); } /** diff --git a/core/modules/update/update.authorize.inc b/core/modules/update/update.authorize.inc index ee1e6fb..ab5f5bc 100644 --- a/core/modules/update/update.authorize.inc +++ b/core/modules/update/update.authorize.inc @@ -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', diff --git a/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc index 9e9d73a..d2c66ee 100644 --- a/core/modules/update/update.manager.inc +++ b/core/modules/update/update.manager.inc @@ -430,9 +430,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'])) {