Completed
Push — master ( 374177...523c73 )
by Joshua
01:44
created

CleanCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace PendoNL\LaravelScheduleLogger\Commands;
4
5
use Carbon\Carbon;
6
use Illuminate\Console\Command;
7
8
class CleanCommand extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'schedulelogger:clean';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Clean up old records from the schedule log.';
23
24
    public function handle()
25
    {
26
        $this->comment('Cleaning schedule log...');
27
28
        $maxAgeInDays = 30;
29
30
        $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
31
32
        $amountDeleted = Schedulelog::where('created_at', '<', $cutOffDate)->delete();
33
34
        $this->info("Deleted {$amountDeleted} record(s) from the schedule log.");
35
36
        $this->comment('All done!');
37
    }
38
}
39