Skip to content

Commit

Permalink
Merge pull request #14 from event-engine/feature/force_replay
Browse files Browse the repository at this point in the history
Force replay when rebuilding AR state
  • Loading branch information
codeliner committed Aug 29, 2019
2 parents 07b994f + 21a4ad2 commit 793775f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/EventEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ public function rebuildAggregateState(string $aggregateType, string $aggregateId
if (null === $aggregateCollection) {
throw MissingAggregateCollection::forAggregate($aggregateType);
}
$aggregateRoot = $this->loadAggregateRoot($aggregateType, $aggregateId);
$aggregateRoot = $this->loadAggregateRoot($aggregateType, $aggregateId, null, true);

$aggregateState = $aggregateRoot->currentState();

Expand Down Expand Up @@ -1019,17 +1019,32 @@ public function loadAggregateStateUntil(string $aggregateType, string $aggregate
return $aggregate->currentState();
}

private function loadAggregateRoot(string $aggregateType, string $aggregateId, int $expectedVersion = null)
private function loadAggregateRoot(string $aggregateType, string $aggregateId, int $expectedVersion = null, bool $forceReplay = false)
{
$aggregateDesc = $this->aggregateDescriptions[$aggregateType];

$multiStoreMode = $aggregateDesc['multiStoreMode'] ?? null;

if($forceReplay) {
if($multiStoreMode === MultiModelStore::STORAGE_MODE_STATE) {
throw new RuntimeException(
"Cannot force replay of aggregate state. Multi store mode for aggregate type $aggregateType is set to "
. MultiModelStore::STORAGE_MODE_STATE
. ". This means that event history is not stored for aggregates of this type!"
);
}

// Override store mode to force replay
$multiStoreMode = MultiModelStore::STORAGE_MODE_EVENTS;
}

$arRepository = new GenericAggregateRepository(
$this->flavour,
$this->eventStore,
$aggregateDesc['aggregateStream'],
$this->documentStore,
$aggregateDesc['aggregateCollection'] ?? null,
$aggregateDesc['multiStoreMode'] ?? null
$multiStoreMode
);

/** @var FlavouredAggregateRoot $aggregate */
Expand Down

0 comments on commit 793775f

Please sign in to comment.