Skip to content

Commit

Permalink
TASK: Simplify normalizeEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 20, 2024
1 parent 2d3a136 commit 46dc510
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function handle(CommandInterface $command): void
// simple case
if ($toPublish instanceof EventsToPublish) {
$eventsToPublish = $this->enrichEventsToPublishWithMetadata($toPublish);
$this->eventStore->commit($eventsToPublish->streamName, $this->eventNormalizer->normalizeEvents($eventsToPublish), $eventsToPublish->expectedVersion);
$this->eventStore->commit($eventsToPublish->streamName, $this->eventNormalizer->normalizeEvents($eventsToPublish->events), $eventsToPublish->expectedVersion);
$catchUpResult = $this->subscriptionEngine->catchUpActive();
if ($catchUpResult->hasErrors()) {
throw new \RuntimeException('Catchup led to errors.. todo', 1731612294);
Expand All @@ -109,7 +109,7 @@ public function handle(CommandInterface $command): void
foreach ($toPublish as $yieldedEventsToPublish) {
$eventsToPublish = $this->enrichEventsToPublishWithMetadata($yieldedEventsToPublish);
try {
$this->eventStore->commit($eventsToPublish->streamName, $this->eventNormalizer->normalizeEvents($eventsToPublish), $eventsToPublish->expectedVersion);
$this->eventStore->commit($eventsToPublish->streamName, $this->eventNormalizer->normalizeEvents($eventsToPublish->events), $eventsToPublish->expectedVersion);
} catch (ConcurrencyException $concurrencyException) {
// we pass the exception into the generator (->throw), so it could be try-caught and reacted upon:
//
Expand All @@ -121,7 +121,7 @@ public function handle(CommandInterface $command): void
// }
$yieldedErrorStrategy = $toPublish->throw($concurrencyException);
if ($yieldedErrorStrategy instanceof EventsToPublish) {
$this->eventStore->commit($yieldedErrorStrategy->streamName, $this->eventNormalizer->normalizeEvents($yieldedErrorStrategy), $yieldedErrorStrategy->expectedVersion);
$this->eventStore->commit($yieldedErrorStrategy->streamName, $this->eventNormalizer->normalizeEvents($yieldedErrorStrategy->events), $yieldedErrorStrategy->expectedVersion);
}
throw $concurrencyException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Neos\ContentRepository\Core\EventStore;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\EventStore\Events as DomainEvents;
use Neos\ContentRepository\Core\Feature\ContentStreamClosing\Event\ContentStreamWasClosed;
use Neos\ContentRepository\Core\Feature\ContentStreamClosing\Event\ContentStreamWasReopened;
use Neos\ContentRepository\Core\Feature\ContentStreamCreation\Event\ContentStreamWasCreated;
Expand Down Expand Up @@ -148,9 +149,9 @@ public function normalize(EventInterface|DecoratedEvent $event): Event
);
}

public function normalizeEvents(EventsToPublish $eventsToPublish): Events
public function normalizeEvents(DomainEvents $events): Events
{
return Events::fromArray($eventsToPublish->events->map($this->normalize(...)));
return Events::fromArray($events->map($this->normalize(...)));
}

public function denormalize(Event $event): EventInterface
Expand Down

0 comments on commit 46dc510

Please sign in to comment.