You are here

MaintenanceModeDisactivate.php in Automatic Updates 8

File

src/Plugin/DatabaseUpdateHandler/MaintenanceModeDisactivate.php
View source
<?php

namespace Drupal\automatic_updates\Plugin\DatabaseUpdateHandler;

use Drupal\automatic_updates\DatabaseUpdateHandlerPluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\State\StateInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Remove site from maintenance mode.
 *
 * @DatabaseUpdateHandler(
 *   id = "maintenance_mode_disactivate",
 *   label = "Remove site from maintenance mode",
 * )
 */
class MaintenanceModeDisactivate extends DatabaseUpdateHandlerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * The state.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * The logger.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Constructs a new maintenance mode service.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state.
   * @param \Psr\Log\LoggerInterface $logger
   *   The logger.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, StateInterface $state, LoggerInterface $logger) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->state = $state;
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('state'), $container
      ->get('logger.channel.automatic_updates'));
  }

  /**
   * {@inheritdoc}
   */
  public function execute() {
    $this->logger
      ->notice('Maintenance mode dis-activated.');
    $this->state
      ->set('system.maintenance_mode', FALSE);
    return TRUE;
  }

}

Classes

Namesort descending Description
MaintenanceModeDisactivate Remove site from maintenance mode.