moe-lk /
bulk-upload
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\Models\Institution; |
||
| 6 | use App\Models\Academic_period; |
||
| 7 | use App\Models\Education_grade; |
||
| 8 | use Illuminate\Console\Command; |
||
| 9 | use App\Models\Institution_class; |
||
| 10 | use App\Models\Institution_student; |
||
| 11 | use App\Models\Institution_subject; |
||
| 12 | use App\Models\Institution_class_student; |
||
| 13 | use App\Models\Institution_subject_student; |
||
| 14 | use App\Models\Institution_student_admission; |
||
| 15 | |||
| 16 | class UpdateStudentsCount extends Command |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * The name and signature of the console command. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $signature = 'students:updateCount {entity} {max}'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The console command description. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $description = 'Update the students count male/female'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Create a new command instance. |
||
| 34 | * |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function __construct() |
||
| 38 | { |
||
| 39 | parent::__construct(); |
||
| 40 | $this->output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
||
|
0 ignored issues
–
show
|
|||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Execute the console command. |
||
| 45 | * |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | public function handle() |
||
| 49 | { |
||
| 50 | $this->output->writeln('#########################################'); |
||
| 51 | if($this->argument('entity') == 'class'){ |
||
| 52 | $classes = Institution_class::get()->toArray(); |
||
| 53 | $func = array($this,'updateCount'); |
||
|
0 ignored issues
–
show
|
|||
| 54 | array_walk($subjects,array($this,'process')); |
||
| 55 | $this->output->writeln('start updating:'. count($classes)); |
||
| 56 | }elseif($this->argument('entity') == 'subject'){ |
||
| 57 | $subjects = Institution_subject::get()->toArray(); |
||
| 58 | $subjects = array_chunk($subjects,10000); |
||
| 59 | $this->output->writeln('start updating:'. count($subjects)); |
||
| 60 | array_walk($subjects,array($this,'process')); |
||
| 61 | $this->output->writeln('#########################################'); |
||
| 62 | } |
||
| 63 | |||
| 64 | } |
||
| 65 | |||
| 66 | public function process($data){ |
||
| 67 | if($this->argument('entity') == 'class'){ |
||
| 68 | $func = array($this,'updateCount'); |
||
| 69 | processParallel($func,$data,$this->argument('max')); |
||
| 70 | $this->output->writeln('start updating calss count:'. count($data)); |
||
| 71 | }elseif($this->argument('entity') == 'subject'){ |
||
| 72 | $this->output->writeln('start updating subject count:'. count($data)); |
||
| 73 | $func_subject = array($this,'updateSubjectCount'); |
||
| 74 | processParallel($func_subject,$data,$this->argument('max')); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | public function updateCount($class){ |
||
| 79 | $this->output->writeln('updating class:'. $class['id']); |
||
| 80 | $totalStudents = Institution_class_student::getStudentsCount($class['id']); |
||
| 81 | Institution_class::where('id', '=', $class['id']) |
||
| 82 | ->update([ |
||
| 83 | 'total_male_students' => $totalStudents['total_male_students'], |
||
| 84 | 'total_female_students' => $totalStudents['total_female_students'] |
||
| 85 | ]); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function updateSubjectCount($subject){ |
||
| 89 | $this->output->writeln('updating subject:'. $subject['id']); |
||
| 90 | $totalStudents = Institution_subject_student::getStudentsCount($subject['id']); |
||
| 91 | Institution_subject::where(['id' => $subject['id']]) |
||
| 92 | ->update([ |
||
| 93 | 'total_male_students' => $totalStudents['total_male_students'], |
||
| 94 | 'total_female_students' => $totalStudents['total_female_students'] |
||
| 95 | ]); |
||
| 96 | } |
||
| 97 | } |
||
| 98 |
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..