Test Setup Failed
Pull Request — master (#537)
by Mohamed
07:44
created

UpdateClassEntriyWithZeroId::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
cc 2
eloc 5
c 4
b 1
f 1
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use App\Models\Institution_class;
7
use Illuminate\Support\Facades\DB;
8
use App\Models\Institution_class_grade;
9
use App\Models\Institution_class_student;
10
11
class UpdateClassEntriyWithZeroId extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'update:zero_id_class';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'update student class reference';
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
        $students = Institution_class_student::where('institution_class_id',0)->get()->toArray();
45
        if(count($students)>0){
46
            processParallel(array($this,'process'),$students,15);
47
        }else{
48
            echo "all are updated \r\n";
49
        }
50
    }
51
52
    public function process($student){
53
        $institutionClass =  Institution_class::getGradeClasses($student['education_grade_id'],$student['institution_id']);
54
        
55
        if(count($institutionClass) == 1){
56
            Institution_class_student::where('student_id',$student['student_id'])
57
            ->update(['institution_class_id' => $institutionClass->id,'education_grade_id' => $student['education_grade_id']]);    
58
        echo "updated:" .$student['student_id']; 
59
        }else{
60
            Institution_class_student::where('student_id',$student['student_id'])->delete();
61
        }
62
    }
63
}
64