From f0cb74dd51007df828168bb7e76f164239a2b919 Mon Sep 17 00:00:00 2001
From: Kunal Sachdev <57170-kunal.sachdev@users.noreply.drupalcode.org>
Date: Thu, 30 Mar 2023 14:01:22 +0000
Subject: [PATCH] Issue #3351093 by kunal.sachdev: Merge
 \Drupal\automatic_updates\EventSubscriber\ConfigSubscriber into StatusChecker

---
 automatic_updates.services.yml           |  4 --
 src/EventSubscriber/ConfigSubscriber.php | 74 ------------------------
 src/Validation/StatusChecker.php         | 32 ++++++++++
 3 files changed, 32 insertions(+), 78 deletions(-)
 delete mode 100644 src/EventSubscriber/ConfigSubscriber.php

diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml
index 4d07d4d0cc..d0d2be5d1a 100644
--- a/automatic_updates.services.yml
+++ b/automatic_updates.services.yml
@@ -57,10 +57,6 @@ services:
     tags:
       - { name: event_subscriber }
   Drupal\automatic_updates\Validator\VersionPolicyValidator: '@automatic_updates.validator.version_policy'
-  automatic_updates.config_subscriber:
-    class: Drupal\automatic_updates\EventSubscriber\ConfigSubscriber
-    tags:
-      - { name: event_subscriber }
   automatic_updates.validator.scaffold_file_permissions:
     class: Drupal\automatic_updates\Validator\ScaffoldFilePermissionsValidator
     tags:
diff --git a/src/EventSubscriber/ConfigSubscriber.php b/src/EventSubscriber/ConfigSubscriber.php
deleted file mode 100644
index 733d4026f3..0000000000
--- a/src/EventSubscriber/ConfigSubscriber.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-declare(strict_types = 1);
-
-namespace Drupal\automatic_updates\EventSubscriber;
-
-use Drupal\automatic_updates\CronUpdater;
-use Drupal\automatic_updates\StatusCheckMailer;
-use Drupal\automatic_updates\Validation\StatusChecker;
-use Drupal\Core\Config\ConfigCrudEvent;
-use Drupal\Core\Config\ConfigEvents;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Clears stored validation results after certain config changes.
- *
- * @todo Move this functionality into StatusChecker when
- *   https://www.drupal.org/i/3275317#comment-14482995 is resolved.
- *
- * @internal
- *   This is an internal part of Automatic Updates and may be changed or removed
- *   at any time without warning. External code should not interact with this
- *   class.
- */
-final class ConfigSubscriber implements EventSubscriberInterface {
-
-  /**
-   * Constructs a ConfigSubscriber object.
-   *
-   * @param \Drupal\automatic_updates\Validation\StatusChecker $statusChecker
-   *   The status checker service.
-   */
-  public function __construct(protected StatusChecker $statusChecker) {
-    $this->statusChecker = $statusChecker;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getSubscribedEvents(): array {
-    return [
-      ConfigEvents::SAVE => 'onConfigSave',
-    ];
-  }
-
-  /**
-   * Reacts when config is saved.
-   *
-   * @param \Drupal\Core\Config\ConfigCrudEvent $event
-   *   The event object.
-   */
-  public function onConfigSave(ConfigCrudEvent $event): void {
-    $config = $event->getConfig();
-
-    // If the path of the Composer executable has changed, the status check
-    // results are likely to change as well.
-    if ($config->getName() === 'package_manager.settings' && $event->isChanged('executables.composer')) {
-      $this->statusChecker->clearStoredResults();
-    }
-    elseif ($config->getName() === 'automatic_updates.settings') {
-      // We only send status check failure notifications if unattended updates
-      // are enabled. If notifications were previously disabled but have been
-      // re-enabled, or their sensitivity level has changed, clear the stored
-      // results so that we'll send accurate notifications next time cron runs.
-      if ($event->isChanged('cron') && $config->getOriginal('cron') === CronUpdater::DISABLED) {
-        $this->statusChecker->clearStoredResults();
-      }
-      elseif ($event->isChanged('status_check_mail') && $config->get('status_check_mail') !== StatusCheckMailer::DISABLED) {
-        $this->statusChecker->clearStoredResults();
-      }
-    }
-  }
-
-}
diff --git a/src/Validation/StatusChecker.php b/src/Validation/StatusChecker.php
index 366c7e4437..444b13ce9e 100644
--- a/src/Validation/StatusChecker.php
+++ b/src/Validation/StatusChecker.php
@@ -5,6 +5,9 @@ declare(strict_types = 1);
 namespace Drupal\automatic_updates\Validation;
 
 use Drupal\automatic_updates\CronUpdater;
+use Drupal\automatic_updates\StatusCheckMailer;
+use Drupal\Core\Config\ConfigCrudEvent;
+use Drupal\Core\Config\ConfigEvents;
 use Drupal\package_manager\StatusCheckTrait;
 use Drupal\automatic_updates\Updater;
 use Drupal\Component\Datetime\TimeInterface;
@@ -136,12 +139,41 @@ final class StatusChecker implements EventSubscriberInterface {
     return $this->keyValueExpirable->get('status_check_timestamp');
   }
 
+  /**
+   * Reacts when config is saved.
+   *
+   * @param \Drupal\Core\Config\ConfigCrudEvent $event
+   *   The event object.
+   */
+  public function onConfigSave(ConfigCrudEvent $event): void {
+    $config = $event->getConfig();
+
+    // If the path of the Composer executable has changed, the status check
+    // results are likely to change as well.
+    if ($config->getName() === 'package_manager.settings' && $event->isChanged('executables.composer')) {
+      $this->clearStoredResults();
+    }
+    elseif ($config->getName() === 'automatic_updates.settings') {
+      // We only send status check failure notifications if unattended updates
+      // are enabled. If notifications were previously disabled but have been
+      // re-enabled, or their sensitivity level has changed, clear the stored
+      // results so that we'll send accurate notifications next time cron runs.
+      if ($event->isChanged('cron') && $config->getOriginal('cron') === CronUpdater::DISABLED) {
+        $this->clearStoredResults();
+      }
+      elseif ($event->isChanged('status_check_mail') && $config->get('status_check_mail') !== StatusCheckMailer::DISABLED) {
+        $this->clearStoredResults();
+      }
+    }
+  }
+
   /**
    * {@inheritdoc}
    */
   public static function getSubscribedEvents() {
     return [
       PostApplyEvent::class => 'clearStoredResults',
+      ConfigEvents::SAVE => 'onConfigSave',
     ];
   }
 
-- 
GitLab