From 750930e8ade340d97ce3865e37a4c5386be2697a Mon Sep 17 00:00:00 2001 From: tedbow <tedbow@240860.no-reply.drupal.org> Date: Tue, 22 Feb 2022 21:22:03 +0000 Subject: [PATCH] Issue #3244679 by tedbow, kunal.sachdev, rkoller: Should readiness checks be displayed on admin pages if cron updates are disabled? --- src/Validation/AdminReadinessMessages.php | 23 +++++++++++++++++-- .../Functional/ReadinessValidationTest.php | 10 ++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Validation/AdminReadinessMessages.php b/src/Validation/AdminReadinessMessages.php index 25c378a5b4..286270a463 100644 --- a/src/Validation/AdminReadinessMessages.php +++ b/src/Validation/AdminReadinessMessages.php @@ -2,6 +2,8 @@ namespace Drupal\automatic_updates\Validation; +use Drupal\automatic_updates\CronUpdater; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Messenger\MessengerTrait; @@ -57,6 +59,13 @@ final class AdminReadinessMessages implements ContainerInjectionInterface { */ protected $currentRouteMatch; + /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $config; + /** * Constructs a ReadinessRequirement object. * @@ -72,14 +81,17 @@ final class AdminReadinessMessages implements ContainerInjectionInterface { * The translation service. * @param \Drupal\Core\Routing\CurrentRouteMatch $current_route_match * The current route match. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config + * The config factory service. */ - public function __construct(ReadinessValidationManager $readiness_checker_manager, MessengerInterface $messenger, AdminContext $admin_context, AccountProxyInterface $current_user, TranslationInterface $translation, CurrentRouteMatch $current_route_match) { + public function __construct(ReadinessValidationManager $readiness_checker_manager, MessengerInterface $messenger, AdminContext $admin_context, AccountProxyInterface $current_user, TranslationInterface $translation, CurrentRouteMatch $current_route_match, ConfigFactoryInterface $config) { $this->readinessCheckerManager = $readiness_checker_manager; $this->setMessenger($messenger); $this->adminContext = $admin_context; $this->currentUser = $current_user; $this->setStringTranslation($translation); $this->currentRouteMatch = $current_route_match; + $this->config = $config; } /** @@ -92,7 +104,8 @@ final class AdminReadinessMessages implements ContainerInjectionInterface { $container->get('router.admin_context'), $container->get('current_user'), $container->get('string_translation'), - $container->get('current_route_match') + $container->get('current_route_match'), + $container->get('config.factory') ); } @@ -127,6 +140,12 @@ final class AdminReadinessMessages implements ContainerInjectionInterface { * Whether the messages should be displayed on the current page. */ protected function displayResultsOnCurrentPage(): bool { + // If updates will not run during cron then we don't need to show the + // readiness checks on admin pages. + if ($this->config->get('automatic_updates.settings')->get('cron') === CronUpdater::DISABLED) { + return FALSE; + } + if ($this->adminContext->isAdminRoute() && $this->currentUser->hasPermission('administer site configuration')) { // These routes don't need additional nagging. $disabled_routes = [ diff --git a/tests/src/Functional/ReadinessValidationTest.php b/tests/src/Functional/ReadinessValidationTest.php index b00c620159..877f98f551 100644 --- a/tests/src/Functional/ReadinessValidationTest.php +++ b/tests/src/Functional/ReadinessValidationTest.php @@ -7,6 +7,7 @@ use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates_test\Datetime\TestTime; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2; +use Drupal\Core\Url; use Drupal\system\SystemManager; use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait; use Drupal\Tests\Traits\Core\CronRunTrait; @@ -291,6 +292,15 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $assert->pageTextContainsOnce(static::$warningsExplanation); $assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]); $assert->pageTextNotContains($expected_results[0]->getSummary()); + + // Confirm readiness messages are not displayed when cron updates are + // disabled. + $this->drupalGet(Url::fromRoute('update.settings')); + $edit['automatic_updates_cron'] = 'disable'; + $this->submitForm($edit, 'Save configuration'); + $this->drupalGet('admin/structure'); + $assert->pageTextNotContains(static::$warningsExplanation); + $assert->pageTextNotContains($expected_results[0]->getMessages()[0]); } /** -- GitLab