@@ 10-46 (lines=37) @@ | ||
7 | use Spatie\EventProjector\EventProjectionist; |
|
8 | use Spatie\EventProjector\Console\Concerns\ReplaysEvents; |
|
9 | ||
10 | class RebuildCommand extends Command |
|
11 | { |
|
12 | use ReplaysEvents; |
|
13 | ||
14 | protected $signature = 'event-projector:rebuild {projectorName*}'; |
|
15 | ||
16 | protected $description = 'Rebuild a projector'; |
|
17 | ||
18 | /** @var \Spatie\EventProjector\EventProjectionist */ |
|
19 | protected $eventProjectionist; |
|
20 | ||
21 | public function __construct(EventProjectionist $eventProjectionist) |
|
22 | { |
|
23 | parent::__construct(); |
|
24 | ||
25 | $this->eventProjectionist = $eventProjectionist; |
|
26 | } |
|
27 | ||
28 | public function handle() |
|
29 | { |
|
30 | $projectorNames = $this->argument('projectorName'); |
|
31 | ||
32 | $projectors = collect($projectorNames) |
|
33 | ->map(function (string $projectorName) { |
|
34 | if (! $projector = $this->eventProjectionist->getProjector($projectorName)) { |
|
35 | throw new Exception("Projector {$projectorName} not found. Did you register?"); |
|
36 | } |
|
37 | ||
38 | return $projector; |
|
39 | }) |
|
40 | ->each->reset(); |
|
41 | ||
42 | $this->replayEvents($projectors); |
|
43 | ||
44 | $this->comment('Projector(s) rebuild!'); |
|
45 | } |
|
46 | } |
|
47 |
@@ 9-41 (lines=33) @@ | ||
6 | use Illuminate\Console\Command; |
|
7 | use Spatie\EventProjector\EventProjectionist; |
|
8 | ||
9 | class ResetCommand extends Command |
|
10 | { |
|
11 | protected $signature = 'event-projector:reset {projectorName*}'; |
|
12 | ||
13 | protected $description = 'Reset a projector'; |
|
14 | ||
15 | /** @var \Spatie\EventProjector\EventProjectionist */ |
|
16 | protected $eventProjectionist; |
|
17 | ||
18 | public function __construct(EventProjectionist $eventProjectionist) |
|
19 | { |
|
20 | parent::__construct(); |
|
21 | ||
22 | $this->eventProjectionist = $eventProjectionist; |
|
23 | } |
|
24 | ||
25 | public function handle() |
|
26 | { |
|
27 | $projectorNames = $this->argument('projectorName'); |
|
28 | ||
29 | collect($projectorNames) |
|
30 | ->map(function (string $projectorName) { |
|
31 | if (! $projector = $this->eventProjectionist->getProjector($projectorName)) { |
|
32 | throw new Exception("Projector {$projectorName} not found. Did you register?"); |
|
33 | } |
|
34 | ||
35 | return $projector; |
|
36 | }) |
|
37 | ->each->reset(); |
|
38 | ||
39 | $this->comment('Projector(s) reset!'); |
|
40 | } |
|
41 | } |
|
42 |