Skip to content
Snippets Groups Projects
Commit 265871b0 authored by omkar podey's avatar omkar podey Committed by Ted Bowman
Browse files

Issue #3306283 by omkar.podey, tedbow: If cron updates are disabled display a...

Issue #3306283 by omkar.podey, tedbow: If cron updates are disabled display a message if status checks fail after installing Automatic Updates
parent 2a2200d8
No related branches found
No related tags found
1 merge request!553Issue #3306283: Display readiness check results if any after installing Automatic Updates
......@@ -196,12 +196,22 @@ function automatic_updates_cron() {
/**
* Implements hook_modules_installed().
*/
function automatic_updates_modules_installed() {
function automatic_updates_modules_installed($modules) {
// Run the status checkers if needed when any modules are installed in
// case they provide status checkers.
/** @var \Drupal\automatic_updates\Validation\StatusChecker $status_checker */
$status_checker = \Drupal::service('automatic_updates.status_checker');
$status_checker->run();
/** @var \Drupal\automatic_updates\CronUpdater $cron_updater */
$cron_updater = \Drupal::service('automatic_updates.cron_updater');
// If cron updates are disabled status check messages will not be displayed on
// admin pages. Therefore, after installing the module the user will not be
// alerted to any problems until they access the status report page.
if ($cron_updater->getMode() === CronUpdater::DISABLED) {
/** @var \Drupal\automatic_updates\Validation\AdminStatusCheckMessages $status_check_messages */
$status_check_messages = \Drupal::classResolver(AdminStatusCheckMessages::class);
$status_check_messages->displayResultSummary();
}
}
/**
......
......@@ -16,6 +16,7 @@ use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Drupal\package_manager\ValidationResult;
use Drupal\system\SystemManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -191,4 +192,34 @@ final class AdminStatusCheckMessages implements ContainerInjectionInterface {
return TRUE;
}
/**
* Displays the result summary.
*/
public function displayResultSummary(): void {
if (!$this->currentUser->hasPermission('administer site configuration')) {
return;
}
$results = $this->statusChecker->getResults();
if (empty($results)) {
return;
}
// First message: severity.
$overall_severity = ValidationResult::getOverallSeverity($results);
$message = $this->getFailureMessageForSeverity($overall_severity);
$message_type = $overall_severity === SystemManager::REQUIREMENT_ERROR ? MessengerInterface::TYPE_ERROR : MessengerInterface::TYPE_WARNING;
$this->messenger()->addMessage($message, $message_type);
// Optional second message: more details (for users with sufficient
// permissions).
$status_report_url = Url::fromRoute('system.status');
if ($status_report_url->access()) {
$this->messenger()->addMessage(
$this->t('<a href=":url">See status report for more details.</a>', [
':url' => $status_report_url->toString(),
]),
$message_type,
);
}
}
}
......@@ -12,6 +12,7 @@ use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2;
use Drupal\Core\Url;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber;
use Drupal\system\SystemManager;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
use Drupal\Tests\Traits\Core\CronRunTrait;
......@@ -53,6 +54,13 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
*/
protected $testChecker;
/**
* {@inheritdoc}
*/
protected static $modules = [
'package_manager_test_validation',
];
/**
* {@inheritdoc}
*/
......@@ -70,10 +78,49 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
'administer software updates',
'access administration pages',
'access site in maintenance mode',
'administer modules',
]);
$this->drupalLogin($this->reportViewerUser);
}
/**
* Tests status checks are displayed after Automatic Updates is installed.
*
* @dataProvider providerTestModuleFormInstallDisplay
*/
public function testModuleFormInstallDisplay(int $results_severity): void {
// Uninstall Automatic Updates as it is installed in TestBase setup().
$this->container->get('module_installer')->uninstall(['automatic_updates']);
$expected_result = $this->createValidationResult($results_severity);
TestSubscriber::setTestResult([$expected_result], StatusCheckEvent::class);
$this->drupalLogin($this->checkerRunnerUser);
$this->drupalGet('admin/modules');
$page = $this->getSession()->getPage();
$page->checkField('modules[automatic_updates][enable]');
$page->pressButton('Install');
// Cron Updates will always be disabled on installation as per
// automatic_updates.settings.yml .
$session = $this->assertSession();
$session->pageTextNotContains($expected_result->getMessages()[0]);
$session->linkExists('See status report for more details.');
}
/**
* Provides data for testModuleFormInstallDisplay.
*/
public function providerTestModuleFormInstallDisplay(): array {
return [
'Error' => [
SystemManager::REQUIREMENT_ERROR,
],
'Warning' => [
SystemManager::REQUIREMENT_WARNING,
],
];
}
/**
* Tests status checks on status report page.
*/
......
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