Skip to content
Snippets Groups Projects
Commit f0cb74dd authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Adam G-H
Browse files

Issue #3351093 by kunal.sachdev: Merge...

Issue #3351093 by kunal.sachdev: Merge \Drupal\automatic_updates\EventSubscriber\ConfigSubscriber into StatusChecker
parent 9662b267
No related branches found
No related tags found
3 merge requests!989Issue #3356804 by phenaproxima: Flag a warning during status check if the...,!807Issue #3351093: Try to move the functionality of \Drupal\automatic_updates\EventSubscriber\ConfigSubscriber in StatusChecker,!548Issue #3310729: Incorrect documentation link in UI in case of Process error
......@@ -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:
......
<?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();
}
}
}
}
......@@ -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',
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment