| Conditions | 1 |
| Paths | 1 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 1.0004 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | 7 | public function handle() |
|
| 18 | { |
||
| 19 | 7 | $this->comment('Cleaning activity log...'); |
|
| 20 | |||
| 21 | 7 | $log = $this->argument('log'); |
|
| 22 | |||
| 23 | 7 | $maxAgeInDays = $this->option('days') ?? config('activitylog.delete_records_older_than_days'); |
|
| 24 | |||
| 25 | 7 | $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s'); |
|
| 26 | |||
| 27 | 7 | $activity = ActivitylogServiceProvider::getActivityModelInstance(); |
|
| 28 | |||
| 29 | 7 | $amountDeleted = $activity::where('created_at', '<', $cutOffDate) |
|
| 30 | ->when($log !== null, function (Builder $query) use ($log) { |
||
| 31 | $query->inLog($log); |
||
| 32 | 7 | }) |
|
| 33 | 7 | ->delete(); |
|
| 34 | |||
| 35 | 7 | $this->info("Deleted {$amountDeleted} record(s) from the activity log."); |
|
| 36 | |||
| 37 | 7 | $this->comment('All done!'); |
|
| 38 | 7 | } |
|
| 39 | } |
||
| 40 |