Completed
Push — master ( 8f2f21...85908a )
by
unknown
11s
created

DailyScan   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
C handle() 0 23 7
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
        // If RECURRENT_PER_RUN is defined and > 0 this many scans are started
48
        // per run
49
        $max_schedule = array_key_exists('RECURRENT_PER_RUN', $_ENV) ? $_ENV['RECURRENT_PER_RUN'] : (getenv('RECURRENT_PER_RUN') | 0);
0 ignored issues
show
Unused Code introduced by
The assignment to $max_schedule is dead and can be removed.
Loading history...
50
        foreach ($domains as $domain) {
51
            /** @var Scan $latestScan */
52
            $latestScan = $domain->scans()->latest()->first();
53
            // TIME CHECK
54
            if ($latestScan && $latestScan instanceof Scan && $latestScan->updated_at > Carbon::now()->addDays(-1)) {
55
                continue;
56
            }
57
            if ($latestScan->created_at > Carbon::now()->addHours(-2)) {
58
                continue;
59
            }
60
            ScanController::startScanJob($domain->token, $domain->domain, true, 10);
61
            $this->info('Scan started for: '.$domain->domain);
62
            $bar->advance();
63
        }
64
        $bar->finish();
65
    }
66
}
67