diff --git a/src/Validator/VersionPolicyValidator.php b/src/Validator/VersionPolicyValidator.php index ebc04ba0752ded51a0352e76a72beb482f308fa0..f56d6d80e17495b870ff41c2997515a1bb533f9a 100644 --- a/src/Validator/VersionPolicyValidator.php +++ b/src/Validator/VersionPolicyValidator.php @@ -148,10 +148,19 @@ final class VersionPolicyValidator implements EventSubscriberInterface { $messages = $this->validateVersion($stage, $target_version); if ($messages) { - $summary = $this->t('Updating from Drupal @installed_version to @target_version is not allowed.', [ - '@installed_version' => $this->getInstalledVersion(), - '@target_version' => $target_version, - ]); + $installed_version = $this->getInstalledVersion(); + + if ($target_version) { + $summary = $this->t('Updating from Drupal @installed_version to @target_version is not allowed.', [ + '@installed_version' => $installed_version, + '@target_version' => $target_version, + ]); + } + else { + $summary = $this->t('Updating from Drupal @installed_version is not allowed.', [ + '@installed_version' => $installed_version, + ]); + } $event->addError($messages, $summary); } } diff --git a/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php b/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php index 9946a95bd31c7ebac4ae361d392e4ca71ec1a597..15d01b7841c2845fe7b9bddbe05cc87b5bcf56b9 100644 --- a/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php +++ b/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php @@ -137,7 +137,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { "$metadata_dir/drupal.9.8.1-security.xml", [CronUpdater::SECURITY, CronUpdater::ALL], [ - $this->createValidationResult('9.7.1', '', [ + $this->createValidationResult('9.7.1', NULL, [ 'The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.', 'See the <a href="/admin/reports/updates">available updates page</a> for available updates.', ]), @@ -148,7 +148,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { "$metadata_dir/drupal.9.8.1-security.xml", [CronUpdater::SECURITY, CronUpdater::ALL], [ - $this->createValidationResult('9.7.1', '', [ + $this->createValidationResult('9.7.1', NULL, [ 'The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.', 'Use the <a href="/admin/modules/automatic-update">update form</a> to update to a supported version.', ]), @@ -439,19 +439,26 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { * * @param string $installed_version * The installed version of Drupal core. - * @param string $target_version - * The target version of Drupal core. + * @param string|null $target_version + * The target version of Drupal core, or NULL if it's not known. * @param string[] $messages * The error messages that the result should contain. * * @return \Drupal\package_manager\ValidationResult * A validation error object with the appropriate summary. */ - private function createValidationResult(string $installed_version, string $target_version, array $messages): ValidationResult { - $summary = t('Updating from Drupal @installed_version to @target_version is not allowed.', [ - '@installed_version' => $installed_version, - '@target_version' => $target_version, - ]); + private function createValidationResult(string $installed_version, ?string $target_version, array $messages): ValidationResult { + if ($target_version) { + $summary = t('Updating from Drupal @installed_version to @target_version is not allowed.', [ + '@installed_version' => $installed_version, + '@target_version' => $target_version, + ]); + } + else { + $summary = t('Updating from Drupal @installed_version is not allowed.', [ + '@installed_version' => $installed_version, + ]); + } return ValidationResult::createError($messages, $summary); }