@@ 8-42 (lines=35) @@ | ||
5 | use Illuminate\Console\Command; |
|
6 | use Spatie\EventProjector\Console\Snapshots\Concerns\ChooseSnapshot; |
|
7 | use Spatie\EventProjector\EventProjectionist; |
|
8 | class ResetProjectorCommand extends Command |
|
9 | { |
|
10 | use ChooseSnapshot; |
|
11 | ||
12 | protected $signature = 'event-projector:reset-projector {projectorName}'; |
|
13 | ||
14 | protected $description = 'Reset a projector'; |
|
15 | ||
16 | /** @var \Spatie\EventProjector\EventProjectionist */ |
|
17 | protected $eventProjectionist; |
|
18 | ||
19 | public function __construct(EventProjectionist $eventProjectionist) |
|
20 | { |
|
21 | parent::__construct(); |
|
22 | ||
23 | $this->eventProjectionist = $eventProjectionist; |
|
24 | } |
|
25 | ||
26 | public function handle() |
|
27 | { |
|
28 | $projectorName = $this->argument('projectorName'); |
|
29 | ||
30 | $projector = $this->eventProjectionist->getProjector($projectorName); |
|
31 | ||
32 | if (! $projector) { |
|
33 | $this->warn("No projector named `{$projectorName}` found!"); |
|
34 | ||
35 | return; |
|
36 | } |
|
37 | ||
38 | $projector->reset(); |
|
39 | ||
40 | $this->comment("Projector reset!"); |
|
41 | } |
|
42 | } |
|
43 |
@@ 11-43 (lines=33) @@ | ||
8 | use Spatie\EventProjector\Snapshots\Snapshot; |
|
9 | use Spatie\EventProjector\Snapshots\SnapshotRepository; |
|
10 | ||
11 | class DeleteSnapshotCommand extends Command |
|
12 | { |
|
13 | use ChooseSnapshot; |
|
14 | ||
15 | protected $signature = 'event-projector:delete-snapshot'; |
|
16 | ||
17 | protected $description = 'Delete a snapshot'; |
|
18 | ||
19 | /** @var \Spatie\EventProjector\Snapshots\SnapshotRepository */ |
|
20 | protected $snapshotRepository; |
|
21 | ||
22 | public function __construct(SnapshotRepository $snapshotRepository) |
|
23 | { |
|
24 | parent::__construct(); |
|
25 | ||
26 | $this->snapshotRepository = $snapshotRepository; |
|
27 | } |
|
28 | ||
29 | public function handle() |
|
30 | { |
|
31 | $snapshots = $this->snapshotRepository->get(); |
|
32 | ||
33 | $snapshot = $this->chooseSnapshot('Which snapshot number would like to delete?', $snapshots); |
|
34 | ||
35 | if (! $snapshot) { |
|
36 | return; |
|
37 | } |
|
38 | ||
39 | $snapshot->delete(); |
|
40 | ||
41 | $this->comment("Snapshot deleted!"); |
|
42 | } |
|
43 | } |
|
44 |
@@ 9-41 (lines=33) @@ | ||
6 | use Spatie\EventProjector\Console\Snapshots\Concerns\ChooseSnapshot; |
|
7 | use Spatie\EventProjector\Snapshots\SnapshotRepository; |
|
8 | ||
9 | class RestoreSnapshotCommand extends Command |
|
10 | { |
|
11 | use ChooseSnapshot; |
|
12 | ||
13 | protected $signature = 'event-projector:restore-snapshot'; |
|
14 | ||
15 | protected $description = 'Restore a snapshot'; |
|
16 | ||
17 | /** @var \Spatie\EventProjector\Console\Snapshots\SnapshotRepository */ |
|
18 | protected $snapshotRepository; |
|
19 | ||
20 | public function __construct(SnapshotRepository $snapshotRepository) |
|
21 | { |
|
22 | parent::__construct(); |
|
23 | ||
24 | $this->snapshotRepository = $snapshotRepository; |
|
25 | } |
|
26 | ||
27 | public function handle() |
|
28 | { |
|
29 | $snapshots = $this->snapshotRepository->get(); |
|
30 | ||
31 | $snapshot = $this->chooseSnapshot('Which snapshot number would like to load?', $snapshots); |
|
32 | ||
33 | if (! $snapshot) { |
|
34 | return; |
|
35 | } |
|
36 | ||
37 | $snapshot->restore(); |
|
38 | ||
39 | $this->info('Snapshot restored!'); |
|
40 | } |
|
41 | } |
|
42 |