1 | <?php |
||
2 | |||
3 | namespace Spatie\DbSnapshots\Commands; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Spatie\DbSnapshots\SnapshotRepository; |
||
7 | |||
8 | class Cleanup extends Command |
||
9 | { |
||
10 | protected $signature = 'snapshot:cleanup {--keep=}'; |
||
11 | |||
12 | protected $description = 'Specify how many snapshots to keep and delete the rest'; |
||
13 | |||
14 | public function handle() |
||
15 | { |
||
16 | $snapshots = app(SnapshotRepository::class)->getAll(); |
||
17 | |||
18 | $keep = $this->option('keep'); |
||
19 | |||
20 | if (! $keep && $keep !== '0') { |
||
21 | $this->warn('No value for option --keep.'); |
||
22 | |||
23 | return; |
||
24 | } |
||
25 | |||
26 | $snapshots->splice($keep)->each(function ($snapshot) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
27 | $snapshot->delete(); |
||
28 | }); |
||
29 | } |
||
30 | } |
||
31 |