Skip to content

Commit

Permalink
BUGFIX: Adjust to renamed correlation- and causationIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Sep 1, 2022
1 parent 0bffd9a commit 82531cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public static function withEventId(DecoratedEvent|EventInterface $event, EventId
return new self($event->innerEvent, $eventId, $event->eventMetadata);
}

public static function withCausationIdentifier(
public static function withCausationId(
DecoratedEvent|EventInterface $event,
EventId $causationIdentifier
EventId $causationId
): self {
$event = self::wrapWithDecoratedEventIfNecessary($event);
$eventMetadata = $event->eventMetadata->value;
$eventMetadata['causationIdentifier'] = $causationIdentifier->value;
$eventMetadata['causationId'] = $causationId->value;

return new self($event->innerEvent, $event->eventId, EventMetadata::fromArray($eventMetadata));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function enrichWithCommand(
Events $events,
): Events {
$processedEvents = [];
$causationIdentifier = null;
$causationId = null;
$i = 0;
foreach ($events as $event) {
if ($event instanceof DecoratedEvent) {
Expand Down Expand Up @@ -77,11 +77,11 @@ public static function enrichWithCommand(
]);
$event = DecoratedEvent::withMetadata($event, $metadata);
// we remember the 1st event's identifier as causation identifier for all the others
$causationIdentifier = $event->eventId;
$causationId = $event->eventId;
} else {
// event 2,3,4,...n get a causation identifier set, as they all originate from the 1st event.
if ($causationIdentifier !== null) {
$event = DecoratedEvent::withCausationIdentifier($event, $causationIdentifier);
if ($causationId !== null) {
$event = DecoratedEvent::withCausationId($event, $causationId);
}
}
$processedEvents[] = $event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public function run(): ProcessorResult
->processMetadata(static function(array $metadata) use ($eventIdMap) {
$processedMetadata = $metadata;
/** @var string|null $causationId */
$causationId = $processedMetadata['causationIdentifier'] ?? null;
$causationId = $processedMetadata['causationId'] ?? null;
if ($causationId !== null && array_key_exists($causationId, $eventIdMap)) {
$processedMetadata['causationIdentifier'] = $eventIdMap[$causationId];
$processedMetadata['causationId'] = $eventIdMap[$causationId];
}
/** @var string|null $correlationId */
$correlationId = $processedMetadata['correlationIdentifier'] ?? null;
$correlationId = $processedMetadata['correlationId'] ?? null;
if ($correlationId !== null && array_key_exists($correlationId, $eventIdMap)) {
$processedMetadata['correlationIdentifier'] = $eventIdMap[$correlationId];
$processedMetadata['correlationId'] = $eventIdMap[$correlationId];
}
return $processedMetadata;
});
Expand Down

0 comments on commit 82531cc

Please sign in to comment.