Skip to content

Commit

Permalink
Merge pull request #463 from solvari/main
Browse files Browse the repository at this point in the history
Pass specified aggregate uuid to resetState while replaying
  • Loading branch information
freekmurze authored May 13, 2024
2 parents f2d1d5c + f8ddeb7 commit 03b96b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion docs/advanced-usage/replaying-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ All [events](/laravel-event-sourcing/v7/advanced-usage/preparing-events/) that i
php artisan event-sourcing:replay App\\Projectors\\AccountBalanceProjector App\\Projectors\\AnotherProjector
```

If your projector has a `resetState` method it will get called before replaying events. You can use that method to reset the state of your projector.
If your projector has a `resetState` method it will get called before replaying events. You can use that method to reset the state of your projector. If you run the replay for a specific aggregate, the specified uuid will be passed as a parameter.

```
public function resetState(?string $aggregateUuid = null): void
{
// reset your projector
}
```

If you want to replay events starting from a certain event you can use the `--from` option when executing `event-sourcing:replay`. If you use this option the `resetState` on projectors will not get called. This package does not track which events have already been processed by which projectors. Be sure not to replay events to projectors that already have handled them.

Expand Down
4 changes: 2 additions & 2 deletions src/Projectionist.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public function replay(
$this->isReplaying = true;

if ($startingFromEventId === 0) {
$projectors->each(function (Projector $projector) {
$projectors->each(function (Projector $projector) use ($aggregateUuid) {
if (method_exists($projector, 'resetState')) {
$projector->resetState();
$projector->resetState($aggregateUuid);
}
});
}
Expand Down

0 comments on commit 03b96b6

Please sign in to comment.