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

Issue #3314764 by phenaproxima, tedbow, omkar.podey: Stop listening to ReadinessCheckEvent

parent f284c45b
No related branches found
No related tags found
No related merge requests found
Showing
with 83 additions and 88 deletions
......@@ -61,66 +61,6 @@ services:
class: Drupal\automatic_updates\ReleaseChooser
arguments:
- '@automatic_updates.validator.version_policy'
automatic_updates.composer_executable_validator:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.composer_executable'
tags:
- { name: event_subscriber }
automatic_updates.settings_validator:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.settings'
tags:
- { name: event_subscriber }
automatic_updates.validator.environment_support:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.environment_support'
tags:
- { name: event_subscriber }
automatic_updates.validator.composer_settings:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.composer_settings'
tags:
- { name: event_subscriber }
automatic_updates.disk_space_validator:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.disk_space'
tags:
- { name: event_subscriber }
automatic_updates.pending_updates_validator:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.pending_updates'
tags:
- { name: event_subscriber }
automatic_updates.validator.file_system_permissions:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.file_system'
tags:
- { name: event_subscriber }
automatic_updates.validator.multisite:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.multisite'
tags:
- { name: event_subscriber }
automatic_updates.validator.symlink:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.symlink'
tags:
- { name: event_subscriber }
automatic_updates.validator.patches:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.patches'
tags:
- { name: event_subscriber }
automatic_updates.cron_frequency_validator:
class: Drupal\automatic_updates\Validator\CronFrequencyValidator
arguments:
......
......@@ -3,7 +3,6 @@
namespace Drupal\automatic_updates_extensions\Form;
use Drupal\automatic_updates\Form\UpdateFormBase;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\Exception\ApplyFailedException;
use Drupal\package_manager\ProjectInfo;
use Drupal\package_manager\ValidationResult;
......@@ -166,10 +165,7 @@ final class UpdateReady extends UpdateFormBase {
// Don't run the status checks once the form has been submitted.
if (!$form_state->getUserInput()) {
$event = new StatusCheckEvent($this->updater);
$this->eventDispatcher->dispatch($event);
/** @var \Drupal\package_manager\ValidationResult[] $results */
$results = $event->getResults();
$results = $this->runStatusCheck($this->updater, $this->eventDispatcher);
// This will have no effect if $results is empty.
$this->displayResults($results, $this->renderer);
// If any errors occurred, return the form early so the user cannot
......
......@@ -2,7 +2,6 @@
namespace Drupal\automatic_updates_extensions\Form;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates\Form\UpdateFormBase;
use Drupal\automatic_updates_extensions\BatchProcessor;
use Drupal\automatic_updates_extensions\ExtensionUpdater;
......@@ -163,9 +162,7 @@ final class UpdaterForm extends UpdateFormBase {
$results = [];
}
else {
$event = new ReadinessCheckEvent($this->extensionUpdater);
$this->eventDispatcher->dispatch($event);
$results = $event->getResults();
$results = $this->runStatusCheck($this->extensionUpdater, $this->eventDispatcher, TRUE);
}
$this->displayResults($results, $this->renderer);
$security_level = ValidationResult::getOverallSeverity($results);
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\automatic_updates_extensions\Functional;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\package_manager_test_validation\StagedDatabaseUpdateValidator;
use Drupal\package_manager\Event\PreApplyEvent;
......@@ -432,7 +431,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertUpdatesCount(1);
$message = t("You've not experienced Shakespeare until you have read him in the original Klingon.");
$error = ValidationResult::createError([$message]);
TestSubscriber1::setTestResult([$error], ReadinessCheckEvent::class);
TestSubscriber1::setTestResult([$error], StatusCheckEvent::class);
$this->getSession()->reload();
$assert->pageTextContains($message);
$assert->pageTextContains(static::$errorsExplanation);
......@@ -450,7 +449,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->checkForUpdates();
$message = t("Warning! Updating this module may cause an error.");
$warning = ValidationResult::createWarning([$message]);
TestSubscriber1::setTestResult([$warning], ReadinessCheckEvent::class);
TestSubscriber1::setTestResult([$warning], StatusCheckEvent::class);
// Navigate to the automatic updates form.
$this->drupalGet('/admin/reports/updates');
$this->clickLink('Update Extensions');
......
......@@ -3,11 +3,11 @@
namespace Drupal\Tests\automatic_updates_extensions\Kernel;
use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
......@@ -165,7 +165,7 @@ class ExtensionUpdaterTest extends AutomaticUpdatesExtensionsKernelTestBase {
$results = [
ValidationResult::createError(['An error of some sorts.']),
];
TestSubscriber::setTestResult($results, $event_class);
TestSubscriber1::setTestResult($results, $event_class);
try {
$extension_updater->begin(['my_module' => '9.8.1']);
$extension_updater->stage();
......
<?php
namespace Drupal\package_manager;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Contains helper methods to run status checks on a stage.
*
* @internal
* This is an internal part of Package Manager and may be changed or removed
* at any time without warning. External code should not use or interact with
* this trait.
*/
trait StatusCheckTrait {
/**
* Runs a status check for a stage and returns the results, if any.
*
* @param \Drupal\package_manager\Stage $stage
* The stage to run the status check for.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* (optional) The event dispatcher service.
* @param bool $do_readiness_check
* (optional) Whether to also run readiness checks for the stage
* (deprecated). Defaults to FALSE.
*
* @return \Drupal\package_manager\ValidationResult[]
* The results of the status check. If a readiness check was also done,
* its results will be included.
*/
protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL, bool $do_readiness_check = FALSE): array {
$event_dispatcher ??= \Drupal::service('event_dispatcher');
$event = new StatusCheckEvent($stage);
$event_dispatcher->dispatch($event);
$results = $event->getResults();
if ($do_readiness_check && class_exists(ReadinessCheckEvent::class) && $event_dispatcher->hasListeners(ReadinessCheckEvent::class)) {
$event = new ReadinessCheckEvent($stage);
$event_dispatcher->dispatch($event);
$results = array_merge($results, $event->getResults());
}
return $results;
}
}
......@@ -13,6 +13,7 @@ use Drupal\package_manager\Event\StatusCheckEvent;
use PhpTuf\ComposerStager\Domain\Exception\ExceptionInterface;
use PhpTuf\ComposerStager\Domain\Service\ProcessOutputCallback\ProcessOutputCallbackInterface;
use PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates the Composer executable is the correct version.
......@@ -22,7 +23,7 @@ use PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface;
* at any time without warning. External code should not interact with this
* class.
*/
final class ComposerExecutableValidator implements PreOperationStageValidatorInterface, ProcessOutputCallbackInterface {
final class ComposerExecutableValidator implements EventSubscriberInterface, ProcessOutputCallbackInterface {
use StringTranslationTrait;
......
......@@ -6,11 +6,12 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates the configuration of the cweagans/composer-patches plugin.
*/
class ComposerPatchesValidator implements PreOperationStageValidatorInterface {
class ComposerPatchesValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -7,6 +7,7 @@ use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates certain Composer settings.
......@@ -16,7 +17,7 @@ use Drupal\package_manager\Event\StatusCheckEvent;
* at any time without warning. External code should not interact with this
* class.
*/
final class ComposerSettingsValidator implements PreOperationStageValidatorInterface {
final class ComposerSettingsValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -10,6 +10,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates that there is enough free disk space to do staging operations.
......@@ -19,7 +20,7 @@ use Drupal\package_manager\PathLocator;
* at any time without warning. External code should not interact with this
* class.
*/
class DiskSpaceValidator implements PreOperationStageValidatorInterface {
class DiskSpaceValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Checks that the environment has support for Package Manager.
......@@ -17,7 +18,7 @@ use Drupal\Core\Url;
* at any time without warning. External code should not interact with this
* class.
*/
final class EnvironmentSupportValidator implements PreOperationStageValidatorInterface {
final class EnvironmentSupportValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -12,6 +12,7 @@ use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Checks that the active lock file is unchanged during stage operations.
......@@ -21,7 +22,7 @@ use Drupal\package_manager\PathLocator;
* at any time without warning. External code should not interact with this
* class.
*/
final class LockFileValidator implements PreOperationStageValidatorInterface {
final class LockFileValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Checks that the current site is not part of a multisite.
......@@ -17,7 +18,7 @@ use Drupal\package_manager\PathLocator;
* at any time without warning. External code should not interact with this
* class.
*/
final class MultisiteValidator implements PreOperationStageValidatorInterface {
final class MultisiteValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -6,6 +6,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates that newly installed packages don't overwrite existing directories.
......@@ -15,7 +16,7 @@ use Drupal\package_manager\PathLocator;
* at any time without warning. External code should not interact with this
* class.
*/
final class OverwriteExistingPackagesValidator implements PreOperationStageValidatorInterface {
final class OverwriteExistingPackagesValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -9,6 +9,7 @@ use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Update\UpdateRegistry;
use Drupal\Core\Url;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates that there are no pending database updates.
......@@ -18,7 +19,7 @@ use Drupal\package_manager\Event\StatusCheckEvent;
* at any time without warning. External code should not interact with this
* class.
*/
final class PendingUpdatesValidator implements PreOperationStageValidatorInterface {
final class PendingUpdatesValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -2,6 +2,8 @@
namespace Drupal\package_manager\Validator;
@trigger_error(__NAMESPACE__ . '\PreOperationStageValidatorInterface is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3316086.', E_USER_DEPRECATED);
use Drupal\package_manager\Event\PreOperationStageEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......
......@@ -8,6 +8,7 @@ use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Checks that Drupal's settings are valid for Package Manager.
......@@ -17,7 +18,7 @@ use Drupal\package_manager\Event\StatusCheckEvent;
* at any time without warning. External code should not interact with this
* class.
*/
final class SettingsValidator implements PreOperationStageValidatorInterface {
final class SettingsValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -13,6 +13,7 @@ use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
use PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Flags errors if the project root or staging area contain symbolic links.
......@@ -25,7 +26,7 @@ use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
* at any time without warning. External code should not interact with this
* class.
*/
class SymlinkValidator implements PreOperationStageValidatorInterface {
class SymlinkValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Checks that the file system is writable.
......@@ -17,7 +18,7 @@ use Drupal\package_manager\PathLocator;
* at any time without warning. External code should not interact with this
* class.
*/
class WritableFileSystemValidator implements PreOperationStageValidatorInterface {
class WritableFileSystemValidator implements EventSubscriberInterface {
use StringTranslationTrait;
......
......@@ -114,8 +114,8 @@ class TestSubscriber implements EventSubscriberInterface {
* The state key under which to store the results for the given event.
*/
protected static function getStateKey(string $event): string {
$parts = explode('\\', $event);
return static::STATE_KEY . array_pop($parts);
$key = hash('sha256', static::class . $event);
return static::STATE_KEY . substr($key, 0, 8);
}
/**
......
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