Passed
Push — master ( 45eca1...10ee28 )
by Thomas
07:06
created

syncLeadStatuses::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Student;
6
use Illuminate\Console\Command;
7
8
class syncLeadStatuses extends Command
9
{
10
    protected $signature = 'academico:resync-statuses';
11
12
    protected $description = 'Student have a computed status, which is stored in the DB for performance reasons. In case statuses get out of sync, this command will resync them.';
13
14
    public function __construct()
15
    {
16
        parent::__construct();
17
    }
18
19
    public function handle()
20
    {
21
        foreach (Student::where('lead_type_id', 1)->get() as $student) {
22
            $student->update(['lead_type_id' => null]);
23
        }
24
25
        foreach (Student::enrolled()->get() as $student) {
26
            $student->update(['lead_type_id' => 1]);
27
        }
28
29
        return Command::SUCCESS;
30
    }
31
}
32