Commit 18d37423 authored by Steven Ayers's avatar Steven Ayers Committed by Steven Ayers
Browse files

Issue #3313060 by bluegeek9: Log nothing when in maintenance mode

parent e0e5c7b2
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Drupal\Core\State\StateInterface;

/**
 * Store visitors data when a request terminates.
@@ -75,6 +76,13 @@ class KernelTerminateSubscriber implements EventSubscriberInterface {
   */
  protected $moduleHandler;

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

  /**
   * {@inheritdoc}
   *
@@ -92,8 +100,10 @@ class KernelTerminateSubscriber implements EventSubscriberInterface {
   *   The admin context object.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler object.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(AccountInterface $current_user, Connection $database, RouteMatchInterface $route_match, TitleResolverInterface $title_resolver, ConfigFactoryInterface $config_factory, AdminContext $admin_context, ModuleHandlerInterface $module_handler) {
  public function __construct(AccountInterface $current_user, Connection $database, RouteMatchInterface $route_match, TitleResolverInterface $title_resolver, ConfigFactoryInterface $config_factory, AdminContext $admin_context, ModuleHandlerInterface $module_handler, StateInterface $state) {
    $this->currentUser = $current_user;
    $this->database = $database;
    $this->routeMatch = $route_match;
@@ -101,6 +111,7 @@ class KernelTerminateSubscriber implements EventSubscriberInterface {
    $this->configFactory = $config_factory;
    $this->adminContext = $admin_context;
    $this->moduleHandler = $module_handler;
    $this->state = $state;
  }

  /**
@@ -110,6 +121,9 @@ class KernelTerminateSubscriber implements EventSubscriberInterface {
   *   The Event to process.
   */
  public function onTerminate(TerminateEvent $event) {
    if (1 == $this->state->get('system.maintenance_mode')) {
      return NULL;
    }
    $this->request = $event->getRequest();
    $config = $this->configFactory->get('visitors.config');
    $exclude_user1 = $config->get('exclude_user1');
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ function visitors_update_8212() {
 * Support IPv6.
 */
function visitors_update_8214(&$sandbox) {
  drupal_flush_all_caches();
  // Retrieves a \Drupal\Core\Database\Connection which is a PDO instance.
  $database = Database::getConnection();

+10 −2
Original line number Diff line number Diff line
services:
  visitors.terminate:
    class: Drupal\visitors\EventSubscriber\KernelTerminateSubscriber
    arguments: ['@current_user', '@database', '@current_route_match', '@title_resolver', '@config.factory', '@router.admin_context', '@module_handler']
    arguments:
      - '@current_user'
      - '@database'
      - '@current_route_match'
      - '@title_resolver'
      - '@config.factory'
      - '@router.admin_context'
      - '@module_handler'
      - '@state'
    tags:
      - { name: event_subscriber }
  visitors.negotiator: