Skip to content

Commit

Permalink
WIP Bugfix: Only reorder NodeAggregateWasRemoved events if the node…
Browse files Browse the repository at this point in the history
… is not recreated afterwards
  • Loading branch information
mhsdesign committed Nov 26, 2024
1 parent a14bbe7 commit 9ea48d0
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,27 @@ public function reorderNodeAggregateWasRemoved(\Closure $outputFn): void
$this->copyEventTable($backupEventTableName);

$liveContentStreamName = ContentStreamEventStreamName::fromContentStreamId($liveWorkspaceContentStreamId)->getEventStreamName();

$duplicateNodeAggregateWasCreated = [];
$allNodeAggregateWasCreated = [];
foreach ($this->eventStore->load($liveContentStreamName, EventStreamFilter::create(EventTypes::create(EventType::fromString('NodeAggregateWithNodeWasCreated')))) as $eventEnvelope) {
$nodeAggregateWasCreated = self::decodeEventPayload($eventEnvelope);
if (isset($allNodeAggregateWasCreated[$nodeAggregateWasCreated['nodeAggregateId']])) {
$duplicateNodeAggregateWasCreated[] = $nodeAggregateWasCreated['nodeAggregateId'];
}
$allNodeAggregateWasCreated[$nodeAggregateWasCreated['nodeAggregateId']] = true;
}

$eventsToReorder = [];
// get all NodeAggregateWasRemoved from the live content stream
$eventsToReorder = iterator_to_array($this->eventStore->load($liveContentStreamName, EventStreamFilter::create(EventTypes::create(EventType::fromString('NodeAggregateWasRemoved')))), false);
foreach ($this->eventStore->load($liveContentStreamName, EventStreamFilter::create(EventTypes::create(EventType::fromString('NodeAggregateWasRemoved')))) as $eventEnvelope) {
$nodeAggregateWasRemoved = self::decodeEventPayload($eventEnvelope);
if (in_array($nodeAggregateWasRemoved['nodeAggregateId'], $duplicateNodeAggregateWasCreated, true)) {
$outputFn(sprintf('Skipped reordering removal for %s because %s has multiple creation events.', $eventEnvelope->sequenceNumber->value, $nodeAggregateWasRemoved['nodeAggregateId']));
continue;
}
$eventsToReorder[] = $eventEnvelope;
}

if (!count($eventsToReorder)) {
$outputFn('Migration was not necessary.');
Expand Down

0 comments on commit 9ea48d0

Please sign in to comment.