Completed
Push — master ( 54bfbf...dbe285 )
by
unknown
44s queued 22s
created

CleanSensordata::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\SensorData;
6
use Illuminate\Console\Command;
7
8
class CleanSensordata extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'sensordata:clean';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Clean up old records from the sensordata table.';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        $this->comment('Cleaning sensordata table...');
42
        
43
        $maxAgeInDays = config('sensordata.delete_records_older_than_days', 365);
44
        $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
45
        $amountDeleted = Sensordata::where('created_at', '<', $cutOffDate)->delete();
46
        
47
        $this->info("Deleted {$amountDeleted} record(s) from the activity log.");
48
        
49
        $this->comment('All done!');
50
    }
51
}
52