From 581e49b662af2b2d008e012be1d928af5eb8bd5c Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 13 Aug 2018 15:05:32 +0200 Subject: [PATCH] commit --- CHANGELOG.md | 4 ++++ src/Console/Concerns/ReplaysEvents.php | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a7372..8a4dfe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Console/Concerns/ReplaysEvents.php b/src/Console/Concerns/ReplaysEvents.php index efb63db..1814fa9 100644 --- a/src/Console/Concerns/ReplaysEvents.php +++ b/src/Console/Concerns/ReplaysEvents.php @@ -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'); @@ -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(); }; @@ -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()) { @@ -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') @@ -82,4 +82,9 @@ protected function emptyLine(int $amount = 1) $this->line(''); } } + + protected function getStoredEventClass(): string + { + return config('event-projector.stored_event_model'); + } }