Completed
Push — master ( 336fac...dd3d41 )
by Marcel
13s
created

DailyScan::handle()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 4
nop 0
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Domain;
6
use App\Http\Controllers\ScanController;
7
use App\Scan;
8
use Illuminate\Console\Command;
9
use Illuminate\Support\Carbon;
10
11
class DailyScan extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'siwecos:dailyscan';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Starts a scan for each activated domain';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    public function handle()
43
    {
44
        $domains = Domain::whereVerified('1')->get();
45
        /** @var Domain $domain */
46
        $bar = $this->output->createProgressBar(\count($domains));
47
        foreach ($domains as $domain) {
48
            /** @var Scan $latestScan */
49
            $latestScan = $domain->scans()->latest()->first();
50
            // TIME CHECK
51
            if ($latestScan && $latestScan instanceof Scan && $latestScan->updated_at > Carbon::now()->addDays(-1)) {
52
                continue;
53
            }
54
            if ($latestScan->created_at > Carbon::now()->addHours(-2)) {
55
                continue;
56
            }
57
            ScanController::startScanJob($domain->token, $domain->domain, true, 10);
58
            $this->info('Scan started for: '.$domain->domain);
59
            $bar->advance();
60
        }
61
        $bar->finish();
62
    }
63
}
64