1 | <?php |
||
2 | |||
3 | namespace App\Console\Commands; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Support\Facades\DB; |
||
7 | use App\Models\Institution_student; |
||
8 | |||
9 | class RemoveDuplications extends Command |
||
10 | { |
||
11 | /** |
||
12 | * The name and signature of the console command. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $signature = 'student:clean {chunk} {max}'; |
||
17 | |||
18 | /** |
||
19 | * The console command description. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $description = 'This command is to clean students data'; |
||
24 | |||
25 | /** |
||
26 | * Create a new command instance. |
||
27 | * |
||
28 | * @return void |
||
29 | */ |
||
30 | public function __construct() |
||
31 | { |
||
32 | parent::__construct(); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Execute the console command. |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function handle() |
||
41 | { |
||
42 | try { |
||
43 | $this->start_time = microtime(TRUE); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
44 | $this->output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
||
0 ignored issues
–
show
It seems like
new Symfony\Component\Co...\Output\ConsoleOutput() of type Symfony\Component\Console\Output\ConsoleOutput is incompatible with the declared type Illuminate\Console\OutputStyle of property $output .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
45 | $this->output->writeln('############### Starting delete Duplication ################'); |
||
46 | $duplicatedStudents = Institution_student::select(DB::raw('count(*) as total'),'student_id','id','academic_period_id','education_grade_id') |
||
47 | ->groupBy('student_id') |
||
48 | ->having('total','>',1) |
||
49 | ->orderBy('student_id') |
||
50 | ->get() |
||
51 | ->toArray(); |
||
52 | if(count($duplicatedStudents)>0){ |
||
53 | processParallel(array($this,'process'),$duplicatedStudents,10); |
||
54 | }else{ |
||
55 | $this->output->writeln('Nothing to Process, all are clean'); |
||
56 | } |
||
57 | } catch (\Throwable $th) { |
||
58 | dd($th); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | public function process($Student){ |
||
63 | Institution_student::where('institution_students.id','>',$Student['id']) |
||
64 | ->where('institution_students.student_id',$Student['student_id']) |
||
65 | ->where('institution_students.academic_period_id',$Student['academic_period_id']) |
||
66 | ->where('institution_students.education_grade_id',$Student['education_grade_id']) |
||
67 | ->delete(); |
||
68 | $this->end_time = microtime(TRUE); |
||
0 ignored issues
–
show
|
|||
69 | $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete'); |
||
70 | } |
||
71 | } |
||
72 |