From 05d7455c18298f717f6d9bbf7e6667b3887ba33c Mon Sep 17 00:00:00 2001 From: Nizar Date: Fri, 15 May 2020 10:53:29 +0530 Subject: [PATCH 1/3] fix instituion on command --- app/Console/Commands/RunAddApprovedStudents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/RunAddApprovedStudents.php b/app/Console/Commands/RunAddApprovedStudents.php index aafdc569..6a5d0069 100755 --- a/app/Console/Commands/RunAddApprovedStudents.php +++ b/app/Console/Commands/RunAddApprovedStudents.php @@ -56,7 +56,7 @@ public function handle() $this->info('adding missing students to the admission ' . $institution->name); $allApprovedStudents = Institution_student_admission::where([ 'status_id' => 124, - 'institution_id' => $institution->institution_id + 'institution_id' => $institution->id ])->get()->toArray(); $allApprovedStudents = array_chunk($allApprovedStudents, 50); array_walk($allApprovedStudents, array($this, 'addStudents')); From f275dcf62fab1bb43f300e4460f1f04fd52974aa Mon Sep 17 00:00:00 2001 From: Nizar Date: Fri, 15 May 2020 19:28:48 +0530 Subject: [PATCH 2/3] send email on terminated files --- app/Console/Commands/ProcessTerminatedFiles.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/ProcessTerminatedFiles.php b/app/Console/Commands/ProcessTerminatedFiles.php index 40d93fe2..d25202d2 100755 --- a/app/Console/Commands/ProcessTerminatedFiles.php +++ b/app/Console/Commands/ProcessTerminatedFiles.php @@ -46,7 +46,7 @@ public function handle() $files = $this->getFiles(); try { if(!empty($files)){ - $this->process($files); + array_walk($files,array($this,'process')); unset($files); exit(); @@ -71,21 +71,14 @@ protected function getFiles(){ $files = Upload::where('is_processed', '=', 3) ->where('is_email_sent','=',0) ->where('updated_at', '<=', Carbon::now()->tz('Asia/Colombo')->subHours(3)) - ->limit(1) + ->limit(50) ->get()->toArray(); - if(!empty($files)){ - DB::beginTransaction(); - DB::table('uploads') - ->where('id', $files[0]['id']) - ->update(['is_processed' => 3,'updated_at' => now()]); - DB::commit(); - } return $files; } protected function process($file){ $time = Carbon::now()->tz('Asia/Colombo'); - $this->processSheet($file[0]); + $this->processSheet($file); $output = new \Symfony\Component\Console\Output\ConsoleOutput(); $now = Carbon::now()->tz('Asia/Colombo'); $output->writeln('=============== Time taken to batch ' .$now->diffInMinutes($time)); @@ -95,7 +88,6 @@ protected function process($file){ protected function processSheet($file){ $this->startTime = Carbon::now()->tz('Asia/Colombo'); $user = User::find($file['security_user_id']); - $this->checkNode($file); $output = new \Symfony\Component\Console\Output\ConsoleOutput(); $output->writeln('##########################################################################################################################'); $output->writeln('Processing the file: '.$file['filename']); From 0c53a783a44d13bf3eafdcbde664e15074adb2b9 Mon Sep 17 00:00:00 2001 From: Nizar Date: Sat, 16 May 2020 11:14:29 +0530 Subject: [PATCH 3/3] fix duplication issue in the --- .../Commands/RunAddApprovedStudents.php | 27 ++++++++++--------- app/Models/Institution_class_student.php | 2 +- app/Models/Institution_student.php | 8 ++++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/RunAddApprovedStudents.php b/app/Console/Commands/RunAddApprovedStudents.php index 6a5d0069..975c9833 100755 --- a/app/Console/Commands/RunAddApprovedStudents.php +++ b/app/Console/Commands/RunAddApprovedStudents.php @@ -74,7 +74,7 @@ protected function addStudent($student){ // dd(Institution_class_student::isDuplicated($student)); $output = new \Symfony\Component\Console\Output\ConsoleOutput(); sleep(1); - if(!(Institution_class_student::isDuplicated($student) > 0)){ + if(!(Institution_student::isDuplicated($student))){ $this->count += 1; $this->student = $student ; try{ @@ -92,17 +92,20 @@ protected function addStudent($student){ 'created_user_id' => $student['created_user_id'], ]); - if(!is_null($student['institution_class_id'])){ - Institution_class_student::create([ - 'student_id' => $student['student_id'], - 'institution_class_id' => $student['institution_class_id'], - 'education_grade_id' => $student['education_grade_id'], - 'academic_period_id' => $student['academic_period_id'], - 'institution_id' =>$student['institution_id'], - 'student_status_id' => 1, - 'created_user_id' => $student['created_user_id'], - ]); - } + if(!(Institution_class_student::isDuplicated($student))){ + if(!is_null($student['institution_class_id'])){ + Institution_class_student::create([ + 'student_id' => $student['student_id'], + 'institution_class_id' => $student['institution_class_id'], + 'education_grade_id' => $student['education_grade_id'], + 'academic_period_id' => $student['academic_period_id'], + 'institution_id' =>$student['institution_id'], + 'student_status_id' => 1, + 'created_user_id' => $student['created_user_id'], + ]); + } + } + $output->writeln(' #################################################### Total number of students updated : '.$this->count.' diff --git a/app/Models/Institution_class_student.php b/app/Models/Institution_class_student.php index 6689d14c..e19e1e0f 100755 --- a/app/Models/Institution_class_student.php +++ b/app/Models/Institution_class_student.php @@ -88,7 +88,7 @@ public static function isDuplicated($inputs){ $exists = self::where('student_id','=',$inputs['student_id']) ->where('institution_class_id',$inputs['institution_class_id']) - ->count(); + ->exist(); return $exists; } diff --git a/app/Models/Institution_student.php b/app/Models/Institution_student.php index a833126c..294122d0 100755 --- a/app/Models/Institution_student.php +++ b/app/Models/Institution_student.php @@ -79,8 +79,10 @@ public static function boot() */ public static function isDuplicated($inputs){ - $exists = self::where('student_id','=',$inputs['student_id'])->count(); - + $exists = self::where('student_id','=',$inputs['student_id']) + ->where('institution_id',$inputs['institution_id']) + ->where('academic_period_id',$inputs['academic_period_id']) + ->exist(); return $exists; } @@ -111,4 +113,6 @@ public function getStudentListToPromote($institutionGrade, $academicPeriod){ ->where('institution_students.academic_period_id', $academicPeriod->id)->get()->toArray(); } + + }