Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 13, 2018
1 parent 642b9ba commit 581e49b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-event-projector` will be documented in this file

## 1.0.4 - 2018-08-13

- fix replaying events using a custom `StoredEvent` model

## 1.0.3 - 2018-08-05

- fixed some typos in the config file
Expand Down
19 changes: 12 additions & 7 deletions src/Console/Concerns/ReplaysEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function replay(Collection $projectors)
{
$afterEventId = $this->determineAfterEventId($projectors);

if ($afterEventId === StoredEvent::getMaxId()) {
if ($afterEventId === $this->getStoredEventClass()::getMaxId()) {
$this->warn('There are no events to replay.');
}

$replayCount = StoredEvent::after($afterEventId)->count();
$replayCount = $this->getStoredEventClass()::after($afterEventId)->count();

if ($replayCount === 0) {
$this->warn('There are no events to replay');
Expand All @@ -31,7 +31,7 @@ public function replay(Collection $projectors)
: $this->comment("Replaying events after stored event id {$afterEventId}...");
$this->emptyLine();

$bar = $this->output->createProgressBar(StoredEvent::after($afterEventId)->count());
$bar = $this->output->createProgressBar($this->getStoredEventClass()::after($afterEventId)->count());
$onEventReplayed = function () use ($bar) {
$bar->advance();
};
Expand All @@ -48,9 +48,9 @@ protected function determineAfterEventId(Collection $projectors): int
{
$projectorsWithoutStatus = collect($projectors)
->filter(function (Projector $projector) {
return ! ProjectorStatus::query()
->where('projector_name', $projector->getName())
->exists();
return !ProjectorStatus::query()
->where('projector_name', $projector->getName())
->exists();
});

if ($projectorsWithoutStatus->isNotEmpty()) {
Expand All @@ -67,7 +67,7 @@ protected function determineAfterEventId(Collection $projectors): int
->count();

if ($allProjectorStatusesCount === $allUpToDateProjectorStatusesCount) {
return StoredEvent::getMaxId();
return $this->getStoredEventClass()::getMaxId();
}

return DB::table('projector_statuses')
Expand All @@ -82,4 +82,9 @@ protected function emptyLine(int $amount = 1)
$this->line('');
}
}

protected function getStoredEventClass(): string
{
return config('event-projector.stored_event_model');
}
}

0 comments on commit 581e49b

Please sign in to comment.