From a303b7e9bc9c41766bcee9c1580ffca3b5b7659a Mon Sep 17 00:00:00 2001 From: phenaproxima <phenaproxima@205645.no-reply.drupal.org> Date: Fri, 22 Apr 2022 13:52:05 +0000 Subject: [PATCH] Issue #3275317 by phenaproxima: If you change the path to the Composer executable, you may still see out-of-date validation errors --- automatic_updates.services.yml | 4 ++ src/EventSubscriber/ConfigSubscriber.php | 39 +++++++++++++++++++ .../ReadinessValidationManagerTest.php | 23 +++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/EventSubscriber/ConfigSubscriber.php diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml index 467b719259..f0efbee5f3 100644 --- a/automatic_updates.services.yml +++ b/automatic_updates.services.yml @@ -137,3 +137,7 @@ services: class: Drupal\automatic_updates\Validator\UpdateReleaseValidator tags: - { name: event_subscriber } + automatic_updates.config_subscriber: + class: Drupal\automatic_updates\EventSubscriber\ConfigSubscriber + tags: + - { name: event_subscriber } diff --git a/src/EventSubscriber/ConfigSubscriber.php b/src/EventSubscriber/ConfigSubscriber.php new file mode 100644 index 0000000000..de06544a53 --- /dev/null +++ b/src/EventSubscriber/ConfigSubscriber.php @@ -0,0 +1,39 @@ +<?php + +namespace Drupal\automatic_updates\EventSubscriber; + +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 ReadinessValidationManager when + * https://www.drupal.org/i/3275317#comment-14482995 is resolved. + */ +class ConfigSubscriber implements EventSubscriberInterface { + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + return [ + ConfigEvents::SAVE => 'onConfigSave', + ]; + } + + /** + * Reacts when config is saved. + * + * @param \Drupal\Core\Config\ConfigCrudEvent $event + * The event object. + */ + public function onConfigSave(ConfigCrudEvent $event): void { + if ($event->getConfig()->getName() === 'package_manager.settings' && $event->isChanged('executables.composer')) { + \Drupal::service('automatic_updates.readiness_validation_manager') + ->clearStoredResults(); + } + } + +} diff --git a/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php b/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php index add1626a4e..9db8368bfc 100644 --- a/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php +++ b/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php @@ -253,4 +253,27 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { $this->assertEmpty($manager->getResults()); } + /** + * Tests that certain config changes clear stored results. + */ + public function testStoredResultsClearedOnConfigChanges(): void { + $this->enableModules(['automatic_updates']); + + $results = $this->testResults['checker_1']['1 error']; + TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class); + $this->assertCheckerResultsFromManager($results, TRUE); + // The results should be stored. + $this->assertCheckerResultsFromManager($results, FALSE); + // Changing the configured path to rsync should not clear the results. + $this->config('package_manager.settings') + ->set('executables.rsync', '/path/to/rsync') + ->save(); + $this->assertCheckerResultsFromManager($results, FALSE); + // Changing the configured path to Composer should clear the results. + $this->config('package_manager.settings') + ->set('executables.composer', '/path/to/composer') + ->save(); + $this->assertNull($this->getResultsFromManager(FALSE)); + } + } -- GitLab