Skip to content
Snippets Groups Projects
Commit 5d1aa914 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3247478 by tedbow, phenaproxima: Only pre-operation events should be...

Issue #3247478 by tedbow, phenaproxima: Only pre-operation events should be able to flag errors that stop an update
parent 0361e19b
No related branches found
No related tags found
1 merge request!114Issue #3247478: Determine how to handle validation error in Post events
Showing
with 65 additions and 73 deletions
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
namespace Drupal\package_manager\EventSubscriber; namespace Drupal\package_manager\EventSubscriber;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\PathLocator; use Drupal\package_manager\PathLocator;
...@@ -12,7 +11,7 @@ use Drupal\package_manager\PathLocator; ...@@ -12,7 +11,7 @@ use Drupal\package_manager\PathLocator;
/** /**
* Checks that the file system is writable. * Checks that the file system is writable.
*/ */
class WritableFileSystemValidator implements StageValidatorInterface { class WritableFileSystemValidator implements PreOperationStageValidatorInterface {
use StringTranslationTrait; use StringTranslationTrait;
...@@ -54,7 +53,7 @@ class WritableFileSystemValidator implements StageValidatorInterface { ...@@ -54,7 +53,7 @@ class WritableFileSystemValidator implements StageValidatorInterface {
* false negatives/positives due to things like SELinux, exotic file * false negatives/positives due to things like SELinux, exotic file
* systems, and so forth. * systems, and so forth.
*/ */
public function validateStage(StageEvent $event): void { public function validateStagePreOperation(PreOperationStageEvent $event): void {
$messages = []; $messages = [];
if (!is_writable($this->appRoot)) { if (!is_writable($this->appRoot)) {
...@@ -69,8 +68,7 @@ class WritableFileSystemValidator implements StageValidatorInterface { ...@@ -69,8 +68,7 @@ class WritableFileSystemValidator implements StageValidatorInterface {
} }
if ($messages) { if ($messages) {
$result = ValidationResult::createError($messages, $this->t('The file system is not writable.')); $event->addError($messages, $this->t('The file system is not writable.'));
$event->addValidationResult($result);
} }
} }
...@@ -79,7 +77,7 @@ class WritableFileSystemValidator implements StageValidatorInterface { ...@@ -79,7 +77,7 @@ class WritableFileSystemValidator implements StageValidatorInterface {
*/ */
public static function getSubscribedEvents() { public static function getSubscribedEvents() {
return [ return [
PreCreateEvent::class => 'validateStage', PreCreateEvent::class => 'validateStagePreOperation',
]; ];
} }
......
...@@ -12,7 +12,6 @@ use Drupal\package_manager\Event\PreCreateEvent; ...@@ -12,7 +12,6 @@ use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreDestroyEvent; use Drupal\package_manager\Event\PreDestroyEvent;
use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
use Drupal\system\SystemManager;
use PhpTuf\ComposerStager\Domain\BeginnerInterface; use PhpTuf\ComposerStager\Domain\BeginnerInterface;
use PhpTuf\ComposerStager\Domain\CleanerInterface; use PhpTuf\ComposerStager\Domain\CleanerInterface;
use PhpTuf\ComposerStager\Domain\CommitterInterface; use PhpTuf\ComposerStager\Domain\CommitterInterface;
...@@ -240,9 +239,9 @@ class Stage { ...@@ -240,9 +239,9 @@ class Stage {
try { try {
$this->eventDispatcher->dispatch($event); $this->eventDispatcher->dispatch($event);
$errors = $event->getResults(SystemManager::REQUIREMENT_ERROR); $results = $event->getResults();
if ($errors) { if ($results) {
throw new StageException($errors); throw new StageException($results);
} }
} }
catch (\Throwable $error) { catch (\Throwable $error) {
......
...@@ -12,6 +12,7 @@ use Drupal\package_manager\Event\PreCreateEvent; ...@@ -12,6 +12,7 @@ use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreDestroyEvent; use Drupal\package_manager\Event\PreDestroyEvent;
use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
use Drupal\system\SystemManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
...@@ -101,8 +102,14 @@ class TestSubscriber implements EventSubscriberInterface { ...@@ -101,8 +102,14 @@ class TestSubscriber implements EventSubscriberInterface {
if ($results instanceof \Throwable) { if ($results instanceof \Throwable) {
throw $results; throw $results;
} }
/** @var \Drupal\package_manager\ValidationResult $result */
foreach ($results as $result) { foreach ($results as $result) {
$event->addValidationResult($result); if ($result->getSeverity() === SystemManager::REQUIREMENT_ERROR) {
$event->addError($result->getMessages(), $result->getSummary());
}
else {
$event->addWarning($result->getMessages(), $result->getSummary());
}
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Tests\package_manager\Kernel; namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Event\ErrorEventInterface;
use Drupal\package_manager\Event\PostApplyEvent; use Drupal\package_manager\Event\PostApplyEvent;
use Drupal\package_manager\Event\PostCreateEvent; use Drupal\package_manager\Event\PostCreateEvent;
use Drupal\package_manager\Event\PostDestroyEvent; use Drupal\package_manager\Event\PostDestroyEvent;
...@@ -11,9 +12,9 @@ use Drupal\package_manager\Event\PreCreateEvent; ...@@ -11,9 +12,9 @@ use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreDestroyEvent; use Drupal\package_manager\Event\PreDestroyEvent;
use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\Event\WarningEventInterface;
use Drupal\package_manager\Stage; use Drupal\package_manager\Stage;
use Drupal\package_manager\StageException; use Drupal\package_manager\StageException;
use Drupal\package_manager\ValidationResult;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
...@@ -75,7 +76,7 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc ...@@ -75,7 +76,7 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
/** /**
* Handles a staging area life cycle event. * Handles a staging area life cycle event.
* *
* @param \Drupal\package_manager\Event\StageEvent $event * @param \Drupal\package_manager\Event\PreOperationStageEvent|\Drupal\package_manager\Event\PostOperationStageEvent $event
* The event object. * The event object.
*/ */
public function handleEvent(StageEvent $event): void { public function handleEvent(StageEvent $event): void {
...@@ -83,12 +84,6 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc ...@@ -83,12 +84,6 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
// The event should have a reference to the stage which fired it. // The event should have a reference to the stage which fired it.
$this->assertSame($event->getStage(), $this->stage); $this->assertSame($event->getStage(), $this->stage);
// Adding a warning to the event, should not trigger an exception.
$result = ValidationResult::createWarning([
'This is a public service announcement, this is only a test.',
]);
$event->addValidationResult($result);
} }
/** /**
...@@ -115,12 +110,12 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc ...@@ -115,12 +110,12 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
} }
/** /**
* Data provider for ::testError(). * Data provider for ::testValidationResults().
* *
* @return string[][] * @return string[][]
* Sets of arguments to pass to the test method. * Sets of arguments to pass to the test method.
*/ */
public function providerError(): array { public function providerValidationResults(): array {
return [ return [
[PreCreateEvent::class], [PreCreateEvent::class],
[PostCreateEvent::class], [PostCreateEvent::class],
...@@ -134,20 +129,24 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc ...@@ -134,20 +129,24 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
} }
/** /**
* Tests that an exception is thrown if an event collects an error. * Tests that an exception is thrown if an event has validation results.
* *
* @param string $event_class * @param string $event_class
* The event class to test. * The event class to test.
* *
* @dataProvider providerError * @dataProvider providerValidationResults
*/ */
public function testError(string $event_class): void { public function testValidationResults(string $event_class): void {
// Set up an event listener which will only flag an error for the event // Set up an event listener which will only flag an error for the event
// class under test. // class under test.
$handler = function (StageEvent $event) use ($event_class): void { $handler = function (StageEvent $event) use ($event_class): void {
if (get_class($event) === $event_class) { if (get_class($event) === $event_class) {
$result = ValidationResult::createError(['Burn, baby, burn']); if ($event instanceof ErrorEventInterface) {
$event->addValidationResult($result); $event->addError([['Burn, baby, burn']]);
}
elseif ($event instanceof WarningEventInterface) {
$event->addWarning(['Be careful about fires.']);
}
} }
}; };
$this->container->get('event_dispatcher') $this->container->get('event_dispatcher')
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
namespace Drupal\automatic_updates\Event; namespace Drupal\automatic_updates\Event;
use Drupal\automatic_updates\Updater; use Drupal\automatic_updates\Updater;
use Drupal\package_manager\Event\StageEvent; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\WarningEventInterface;
use Drupal\package_manager\ValidationResult;
/** /**
* Event fired when checking if the site could perform an update. * Event fired when checking if the site could perform an update.
...@@ -17,7 +20,7 @@ use Drupal\package_manager\Event\StageEvent; ...@@ -17,7 +20,7 @@ use Drupal\package_manager\Event\StageEvent;
* *
* @see \Drupal\automatic_updates\Validation\ReadinessValidationManager * @see \Drupal\automatic_updates\Validation\ReadinessValidationManager
*/ */
class ReadinessCheckEvent extends StageEvent { class ReadinessCheckEvent extends PreOperationStageEvent implements WarningEventInterface {
/** /**
* The desired package versions to update to, keyed by package name. * The desired package versions to update to, keyed by package name.
...@@ -50,4 +53,11 @@ class ReadinessCheckEvent extends StageEvent { ...@@ -50,4 +53,11 @@ class ReadinessCheckEvent extends StageEvent {
return $this->packageVersions; return $this->packageVersions;
} }
/**
* {@inheritdoc}
*/
public function addWarning(array $messages, ?TranslatableMarkup $summary = NULL) {
$this->results[] = ValidationResult::createWarning($messages, $summary);
}
} }
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\automatic_updates\Validator; namespace Drupal\automatic_updates\Validator;
use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
...@@ -29,10 +28,9 @@ class CoreComposerValidator implements EventSubscriberInterface { ...@@ -29,10 +28,9 @@ class CoreComposerValidator implements EventSubscriberInterface {
['drupal/core', 'drupal/core-recommended'] ['drupal/core', 'drupal/core-recommended']
); );
if (empty($core_requirements)) { if (empty($core_requirements)) {
$error = ValidationResult::createError([ $event->addError([
$this->t('Drupal core does not appear to be required in the project-level composer.json.'), $this->t('Drupal core does not appear to be required in the project-level composer.json.'),
]); ]);
$event->addValidationResult($error);
} }
} }
......
...@@ -11,7 +11,6 @@ use Drupal\Core\State\StateInterface; ...@@ -11,7 +11,6 @@ use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\package_manager\ValidationResult;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
...@@ -136,12 +135,10 @@ class CronFrequencyValidator implements EventSubscriberInterface { ...@@ -136,12 +135,10 @@ class CronFrequencyValidator implements EventSubscriberInterface {
$interval = $this->configFactory->get('automated_cron.settings')->get('interval'); $interval = $this->configFactory->get('automated_cron.settings')->get('interval');
if ($interval > static::ERROR_INTERVAL) { if ($interval > static::ERROR_INTERVAL) {
$error = ValidationResult::createError([$message]); $event->addError([$message]);
$event->addValidationResult($error);
} }
elseif ($interval > static::WARNING_INTERVAL) { elseif ($interval > static::WARNING_INTERVAL) {
$warning = ValidationResult::createWarning([$message]); $event->addWarning([$message]);
$event->addValidationResult($warning);
} }
} }
...@@ -162,13 +159,12 @@ class CronFrequencyValidator implements EventSubscriberInterface { ...@@ -162,13 +159,12 @@ class CronFrequencyValidator implements EventSubscriberInterface {
// last cron run time is recorded after cron runs. Address this in // last cron run time is recorded after cron runs. Address this in
// https://www.drupal.org/project/automatic_updates/issues/3248544. // https://www.drupal.org/project/automatic_updates/issues/3248544.
if ($this->time->getRequestTime() - $cron_last > static::WARNING_INTERVAL) { if ($this->time->getRequestTime() - $cron_last > static::WARNING_INTERVAL) {
$error = ValidationResult::createError([ $event->addError([
$this->t('Cron has not run recently. For more information, see the online handbook entry for <a href=":cron-handbook">configuring cron jobs</a> to run at least every @frequency hours.', [ $this->t('Cron has not run recently. For more information, see the online handbook entry for <a href=":cron-handbook">configuring cron jobs</a> to run at least every @frequency hours.', [
':cron-handbook' => 'https://www.drupal.org/cron', ':cron-handbook' => 'https://www.drupal.org/cron',
'@frequency' => static::SUGGESTED_INTERVAL, '@frequency' => static::SUGGESTED_INTERVAL,
]), ]),
]); ]);
$event->addValidationResult($error);
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace Drupal\automatic_updates\Validator; namespace Drupal\automatic_updates\Validator;
use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\package_manager\EventSubscriber\StageValidatorInterface; use Drupal\package_manager\EventSubscriber\PreOperationStageValidatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
...@@ -18,17 +18,17 @@ class PackageManagerReadinessCheck implements EventSubscriberInterface { ...@@ -18,17 +18,17 @@ class PackageManagerReadinessCheck implements EventSubscriberInterface {
/** /**
* The validator to run. * The validator to run.
* *
* @var \Drupal\package_manager\EventSubscriber\StageValidatorInterface * @var \Drupal\package_manager\EventSubscriber\PreOperationStageValidatorInterface
*/ */
protected $validator; protected $validator;
/** /**
* Constructs a PackageManagerReadinessCheck object. * Constructs a PackageManagerReadinessCheck object.
* *
* @param \Drupal\package_manager\EventSubscriber\StageValidatorInterface $validator * @param \Drupal\package_manager\EventSubscriber\PreOperationStageValidatorInterface $validator
* The Package Manager validator to run during readiness checking. * The Package Manager validator to run during readiness checking.
*/ */
public function __construct(StageValidatorInterface $validator) { public function __construct(PreOperationStageValidatorInterface $validator) {
$this->validator = $validator; $this->validator = $validator;
} }
...@@ -39,7 +39,7 @@ class PackageManagerReadinessCheck implements EventSubscriberInterface { ...@@ -39,7 +39,7 @@ class PackageManagerReadinessCheck implements EventSubscriberInterface {
* The event object. * The event object.
*/ */
public function validate(ReadinessCheckEvent $event): void { public function validate(ReadinessCheckEvent $event): void {
$this->validator->validateStage($event); $this->validator->validateStagePreOperation($event);
} }
/** /**
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\automatic_updates\Validator; namespace Drupal\automatic_updates\Validator;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
...@@ -38,10 +37,9 @@ final class StagedProjectsValidator implements EventSubscriberInterface { ...@@ -38,10 +37,9 @@ final class StagedProjectsValidator implements EventSubscriberInterface {
$staged_packages = $stage->getStageComposer()->getDrupalExtensionPackages(); $staged_packages = $stage->getStageComposer()->getDrupalExtensionPackages();
} }
catch (\Throwable $e) { catch (\Throwable $e) {
$result = ValidationResult::createError([ $event->addError([
$e->getMessage(), $e->getMessage(),
]); ]);
$event->addValidationResult($result);
return; return;
} }
...@@ -69,7 +67,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface { ...@@ -69,7 +67,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface {
'The update cannot proceed because the following Drupal project was installed during the update.', 'The update cannot proceed because the following Drupal project was installed during the update.',
'The update cannot proceed because the following Drupal projects were installed during the update.' 'The update cannot proceed because the following Drupal projects were installed during the update.'
); );
$event->addValidationResult(ValidationResult::createError($new_packages_messages, $new_packages_summary)); $event->addError($new_packages_messages, $new_packages_summary);
} }
// Check if any Drupal projects were removed. // Check if any Drupal projects were removed.
...@@ -89,7 +87,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface { ...@@ -89,7 +87,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface {
'The update cannot proceed because the following Drupal project was removed during the update.', 'The update cannot proceed because the following Drupal project was removed during the update.',
'The update cannot proceed because the following Drupal projects were removed during the update.' 'The update cannot proceed because the following Drupal projects were removed during the update.'
); );
$event->addValidationResult(ValidationResult::createError($removed_packages_messages, $removed_packages_summary)); $event->addError($removed_packages_messages, $removed_packages_summary);
} }
// Get all the packages that are neither newly installed or removed to // Get all the packages that are neither newly installed or removed to
...@@ -115,7 +113,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface { ...@@ -115,7 +113,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface {
'The update cannot proceed because the following Drupal project was unexpectedly updated. Only Drupal Core updates are currently supported.', 'The update cannot proceed because the following Drupal project was unexpectedly updated. Only Drupal Core updates are currently supported.',
'The update cannot proceed because the following Drupal projects were unexpectedly updated. Only Drupal Core updates are currently supported.' 'The update cannot proceed because the following Drupal projects were unexpectedly updated. Only Drupal Core updates are currently supported.'
); );
$event->addValidationResult(ValidationResult::createError($version_change_messages, $version_change_summary)); $event->addError($version_change_messages, $version_change_summary);
} }
} }
} }
......
...@@ -6,8 +6,7 @@ use Composer\Semver\Semver; ...@@ -6,8 +6,7 @@ use Composer\Semver\Semver;
use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates\Updater; use Drupal\automatic_updates\Updater;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\Core\Extension\ExtensionVersion; use Drupal\Core\Extension\ExtensionVersion;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
...@@ -48,10 +47,10 @@ class UpdateVersionValidator implements EventSubscriberInterface { ...@@ -48,10 +47,10 @@ class UpdateVersionValidator implements EventSubscriberInterface {
/** /**
* Validates that core is not being updated to another minor or major version. * Validates that core is not being updated to another minor or major version.
* *
* @param \Drupal\package_manager\Event\StageEvent $event * @param \Drupal\package_manager\Event\PreOperationStageEvent $event
* The event object. * The event object.
*/ */
public function checkUpdateVersion(StageEvent $event): void { public function checkUpdateVersion(PreOperationStageEvent $event): void {
$stage = $event->getStage(); $stage = $event->getStage();
// We only want to do this check if the stage belongs to Automatic Updates. // We only want to do this check if the stage belongs to Automatic Updates.
if (!$stage instanceof Updater) { if (!$stage instanceof Updater) {
...@@ -85,32 +84,28 @@ class UpdateVersionValidator implements EventSubscriberInterface { ...@@ -85,32 +84,28 @@ class UpdateVersionValidator implements EventSubscriberInterface {
'@to_version' => $to_version_string, '@to_version' => $to_version_string,
'@from_version' => $from_version_string, '@from_version' => $from_version_string,
]); ]);
$error = ValidationResult::createError($messages); $event->addError($messages);
$event->addValidationResult($error);
} }
elseif ($from_version->getVersionExtra() === 'dev') { elseif ($from_version->getVersionExtra() === 'dev') {
$messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from a dev version to any other version are not supported.', [ $messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from a dev version to any other version are not supported.', [
'@to_version' => $to_version_string, '@to_version' => $to_version_string,
'@from_version' => $from_version_string, '@from_version' => $from_version_string,
]); ]);
$error = ValidationResult::createError($messages); $event->addError($messages);
$event->addValidationResult($error);
} }
elseif ($from_version->getMajorVersion() !== $to_version->getMajorVersion()) { elseif ($from_version->getMajorVersion() !== $to_version->getMajorVersion()) {
$messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from one major version to another are not supported.', [ $messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from one major version to another are not supported.', [
'@to_version' => $to_version_string, '@to_version' => $to_version_string,
'@from_version' => $from_version_string, '@from_version' => $from_version_string,
]); ]);
$error = ValidationResult::createError($messages); $event->addError($messages);
$event->addValidationResult($error);
} }
elseif ($from_version->getMinorVersion() !== $to_version->getMinorVersion()) { elseif ($from_version->getMinorVersion() !== $to_version->getMinorVersion()) {
$messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from one minor version to another are not supported.', [ $messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from one minor version to another are not supported.', [
'@from_version' => $this->getCoreVersion(), '@from_version' => $this->getCoreVersion(),
'@to_version' => $package_versions[$core_package_name], '@to_version' => $package_versions[$core_package_name],
]); ]);
$error = ValidationResult::createError($messages); $event->addError($messages);
$event->addValidationResult($error);
} }
} }
......
...@@ -204,14 +204,6 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -204,14 +204,6 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
// Since there's only one message, we shouldn't see the summary. // Since there's only one message, we shouldn't see the summary.
$assert_session->pageTextNotContains($expected_results[0]->getSummary()); $assert_session->pageTextNotContains($expected_results[0]->getSummary());
$assert_session->pageTextContainsOnce((string) $expected_results[0]->getMessages()[0]); $assert_session->pageTextContainsOnce((string) $expected_results[0]->getMessages()[0]);
// If a validator flags a warning, but doesn't throw, the update should
// continue.
$expected_results = $this->testResults['checker_1']['1 warning'];
TestChecker1::setTestResult($expected_results, PreCreateEvent::class);
$page->pressButton('Update');
$this->checkForMetaRefresh();
$assert_session->pageTextContains('Ready to update');
} }
/** /**
......
...@@ -4,7 +4,7 @@ namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; ...@@ -4,7 +4,7 @@ namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation;
use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\package_manager\EventSubscriber\StageValidatorInterface; use Drupal\package_manager\EventSubscriber\PreOperationStageValidatorInterface;
use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
use Prophecy\Argument; use Prophecy\Argument;
...@@ -65,8 +65,8 @@ class PackageManagerReadinessChecksTest extends AutomaticUpdatesKernelTestBase { ...@@ -65,8 +65,8 @@ class PackageManagerReadinessChecksTest extends AutomaticUpdatesKernelTestBase {
// that it gets called with a readiness check event, when we run readiness // that it gets called with a readiness check event, when we run readiness
// checks. // checks.
$event = Argument::type(ReadinessCheckEvent::class); $event = Argument::type(ReadinessCheckEvent::class);
$validator = $this->prophesize(StageValidatorInterface::class); $validator = $this->prophesize(PreOperationStageValidatorInterface::class);
$validator->validateStage($event)->shouldBeCalled(); $validator->validateStagePreOperation($event)->shouldBeCalled();
$this->container->set($service_id, $validator->reveal()); $this->container->set($service_id, $validator->reveal());
$this->container->get('automatic_updates.readiness_validation_manager') $this->container->get('automatic_updates.readiness_validation_manager')
......
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