Conditions | 2 |
Paths | 1 |
Total Lines | 26 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | public function handle() |
||
29 | { |
||
30 | DB::transaction(function () { |
||
31 | $class = $this->getModelArgument(); |
||
32 | |||
33 | $models = ($class)::all(); |
||
34 | |||
35 | if ($models->count() === 0) { |
||
36 | $this->info('Nothing to update.'); |
||
37 | |||
38 | return; |
||
39 | } |
||
40 | |||
41 | $this->line("Analyzing and flushing sequence values from {$models->count()} object(s)."); |
||
42 | |||
43 | $columnName = ($class)::getSequenceColumnName(); |
||
44 | |||
45 | $modelsToUpdate = $models->where($columnName, '!=', null); |
||
46 | |||
47 | $modelsToUpdate->each(function ($model) use ($columnName) { |
||
48 | $model->withoutSequencing()->update([ |
||
49 | $columnName => null, |
||
50 | ]); |
||
51 | }); |
||
52 | |||
53 | $this->info("{$modelsToUpdate->count()} row(s) were updated."); |
||
54 | }); |
||
57 |