You are here

class AdvisoriesConfigSubscriber in Drupal 9

Defines a config subscriber for changes to 'system.advisories'.

Hierarchy

  • class \Drupal\system\EventSubscriber\AdvisoriesConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of AdvisoriesConfigSubscriber

1 string reference to 'AdvisoriesConfigSubscriber'
system.services.yml in core/modules/system/system.services.yml
core/modules/system/system.services.yml
1 service uses AdvisoriesConfigSubscriber
system.advisories_config_subscriber in core/modules/system/system.services.yml
Drupal\system\EventSubscriber\AdvisoriesConfigSubscriber

File

core/modules/system/src/EventSubscriber/AdvisoriesConfigSubscriber.php, line 13

Namespace

Drupal\system\EventSubscriber
View source
class AdvisoriesConfigSubscriber implements EventSubscriberInterface {

  /**
   * The security advisory fetcher service.
   *
   * @var \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher
   */
  protected $securityAdvisoriesFetcher;

  /**
   * Constructs a new ConfigSubscriber object.
   *
   * @param \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher $security_advisories_fetcher
   *   The security advisory fetcher service.
   */
  public function __construct(SecurityAdvisoriesFetcher $security_advisories_fetcher) {
    $this->securityAdvisoriesFetcher = $security_advisories_fetcher;
  }

  /**
   * Deletes the stored response from the security advisories feed, if needed.
   *
   * The stored response will only be deleted if the 'interval_hours' config
   * setting is reduced from the previous value.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The configuration event.
   */
  public function onConfigSave(ConfigCrudEvent $event) : void {
    $saved_config = $event
      ->getConfig();
    if ($saved_config
      ->getName() === 'system.advisories' && $event
      ->isChanged('interval_hours')) {
      $original_interval = $saved_config
        ->getOriginal('interval_hours');
      if ($original_interval && $saved_config
        ->get('interval_hours') < $original_interval) {

        // If the new interval is less than the original interval, delete the
        // stored results.
        $this->securityAdvisoriesFetcher
          ->deleteStoredResponse();
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() : array {
    $events[ConfigEvents::SAVE][] = [
      'onConfigSave',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdvisoriesConfigSubscriber::$securityAdvisoriesFetcher protected property The security advisory fetcher service.
AdvisoriesConfigSubscriber::getSubscribedEvents public static function
AdvisoriesConfigSubscriber::onConfigSave public function Deletes the stored response from the security advisories feed, if needed.
AdvisoriesConfigSubscriber::__construct public function Constructs a new ConfigSubscriber object.