Skip to content
Snippets Groups Projects

Issue #3231153: Simplify dispatching

1 file
+ 6
15
Compare changes
  • Side-by-side
  • Inline
+ 6
15
@@ -25,16 +25,6 @@ class Updater {
@@ -25,16 +25,6 @@ class Updater {
use StringTranslationTrait;
use StringTranslationTrait;
/**
* The event classes to dispatch for various update events.
*
* @var string[]
*/
protected const EVENT_CLASSES = [
AutomaticUpdatesEvents::PRE_START => PreStartEvent::class,
AutomaticUpdatesEvents::PRE_COMMIT => PreCommitEvent::class,
];
/**
/**
* The state key in which to store the status of the update.
* The state key in which to store the status of the update.
*
*
@@ -178,7 +168,8 @@ class Updater {
@@ -178,7 +168,8 @@ class Updater {
}
}
$packages[] = 'drupal/core:' . $project_versions['drupal'];
$packages[] = 'drupal/core:' . $project_versions['drupal'];
$stage_key = $this->createActiveStage($packages);
$stage_key = $this->createActiveStage($packages);
$event = $this->dispatchUpdateEvent(AutomaticUpdatesEvents::PRE_START);
/** @var \Drupal\automatic_updates\Event\PreStartEvent $event */
 
$event = $this->dispatchUpdateEvent(new PreStartEvent(), AutomaticUpdatesEvents::PRE_START);
$this->beginner->begin(static::getActiveDirectory(), static::getStageDirectory(), $this->getExclusions($event));
$this->beginner->begin(static::getActiveDirectory(), static::getStageDirectory(), $this->getExclusions($event));
return $stage_key;
return $stage_key;
}
}
@@ -224,7 +215,7 @@ class Updater {
@@ -224,7 +215,7 @@ class Updater {
*/
*/
public function commit(): void {
public function commit(): void {
/** @var \Drupal\automatic_updates\Event\PreCommitEvent $event */
/** @var \Drupal\automatic_updates\Event\PreCommitEvent $event */
$event = $this->dispatchUpdateEvent(AutomaticUpdatesEvents::PRE_COMMIT);
$event = $this->dispatchUpdateEvent(new PreCommitEvent(), AutomaticUpdatesEvents::PRE_COMMIT);
// @todo Pass excluded paths into the committer once
// @todo Pass excluded paths into the committer once
// https://github.com/php-tuf/composer-stager/pull/14 is in a tagged release
// https://github.com/php-tuf/composer-stager/pull/14 is in a tagged release
// of Composer Stager.
// of Composer Stager.
@@ -278,6 +269,8 @@ class Updater {
@@ -278,6 +269,8 @@ class Updater {
/**
/**
* Dispatches an update event.
* Dispatches an update event.
*
*
 
* @param \Drupal\automatic_updates\Event\UpdateEvent $event
 
* The update event.
* @param string $event_name
* @param string $event_name
* The name of the event to dispatch.
* The name of the event to dispatch.
*
*
@@ -287,9 +280,7 @@ class Updater {
@@ -287,9 +280,7 @@ class Updater {
* @throws \Drupal\automatic_updates\Exception\UpdateException
* @throws \Drupal\automatic_updates\Exception\UpdateException
* If any of the event subscribers adds a validation error.
* If any of the event subscribers adds a validation error.
*/
*/
public function dispatchUpdateEvent(string $event_name): UpdateEvent {
public function dispatchUpdateEvent(UpdateEvent $event, string $event_name): UpdateEvent {
$class = static::EVENT_CLASSES[$event_name] ?? UpdateEvent::class;
$event = new $class();
$this->eventDispatcher->dispatch($event, $event_name);
$this->eventDispatcher->dispatch($event, $event_name);
if ($checker_results = $event->getResults(SystemManager::REQUIREMENT_ERROR)) {
if ($checker_results = $event->getResults(SystemManager::REQUIREMENT_ERROR)) {
throw new UpdateException($checker_results,
throw new UpdateException($checker_results,
Loading