|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Lsf\UniqueUid\UniqueUid; |
|
6
|
|
|
use App\Models\Security_user; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
use App\Models\Examination_student; |
|
10
|
|
|
use App\Models\Institution_student; |
|
11
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
12
|
|
|
use App\Models\Institution_class_student; |
|
13
|
|
|
use App\Models\Institution_student_admission; |
|
14
|
|
|
|
|
15
|
|
|
class CleanExamData extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The name and signature of the console command. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $signature = 'examination:clean {chunk} {max} {type}'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The console command description. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $description = 'Clean SIS data duplication after Exam import'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Create a new command instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct(); |
|
39
|
|
|
$this->output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Execute the console command. |
|
44
|
|
|
* |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
public function handle() |
|
48
|
|
|
{ |
|
49
|
|
|
$type = $this->argument('type'); |
|
50
|
|
|
$students = array(); |
|
51
|
|
|
if($type == 'invalid'){ |
|
52
|
|
|
$students = DB::table('examination_students as es') |
|
53
|
|
|
->whereRaw('CHAR_LENGTH(nsid) > 11') |
|
54
|
|
|
->get() |
|
55
|
|
|
->toArray(); |
|
56
|
|
|
}elseif($type == 'duplicate'){ |
|
57
|
|
|
$students = DB::table('institution_students as is') |
|
58
|
|
|
->join('security_users as su', 'su.id', 'is.student_id') |
|
59
|
|
|
->where('is.updated_from', 'doe') |
|
60
|
|
|
->orWhere('su.updated_from', 'doe') |
|
61
|
|
|
->groupBy('is.student_id') |
|
62
|
|
|
->orderBy('is.student_id') |
|
63
|
|
|
->get() |
|
64
|
|
|
->toArray(); |
|
65
|
|
|
|
|
66
|
|
|
}elseif('all'){ |
|
67
|
|
|
$students = DB::table('examination_students') |
|
68
|
|
|
->where('nsid','<>','') |
|
69
|
|
|
->whereNotNull('nsid') |
|
70
|
|
|
->get() |
|
71
|
|
|
->toArray(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$this->output->writeln('###########################################------Start cleanning exam records------###########################################'); |
|
75
|
|
|
if(count($students) > 0){ |
|
76
|
|
|
$this->output->writeln('Total students to clean: '. count($students)); |
|
77
|
|
|
$students = array_chunk($students, $this->argument('chunk')); |
|
78
|
|
|
$function = array($this, 'process'); |
|
79
|
|
|
processParallel($function,$students, $this->argument('max')); |
|
80
|
|
|
}else{ |
|
81
|
|
|
$this->output->writeln('nothing to process, all are cleaned'); |
|
82
|
|
|
} |
|
83
|
|
|
$this->output->writeln('###########################################------Finished cleaning exam records------###########################################'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function process($students){ |
|
87
|
|
|
$type = $this->argument('type'); |
|
88
|
|
|
if($type == 'duplication'){ |
|
89
|
|
|
array_walk($students,array($this,'cleanData')); |
|
90
|
|
|
}elseif($type == 'invalid' || 'all'){ |
|
91
|
|
|
array_walk($students,array($this,'cleanInvalidData')); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
public function cleanData($Student) |
|
97
|
|
|
{ |
|
98
|
|
|
$exist = Examination_student::where('nsid','=', $Student->openemis_no)->count(); |
|
99
|
|
|
|
|
100
|
|
|
if (!$exist) { |
|
101
|
|
|
Institution_student::where('student_id', $Student->student_id)->delete(); |
|
102
|
|
|
Institution_class_student::where('student_id', $Student->student_id)->delete(); |
|
103
|
|
|
Institution_student_admission::where('student_id', $Student->student_id)->delete(); |
|
104
|
|
|
Security_user::where('id', $Student->student_id)->delete(); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function cleanInvalidData($Student) |
|
109
|
|
|
{ |
|
110
|
|
|
$Student = (array) $Student; |
|
111
|
|
|
$exist = Examination_student::where('nsid',$Student['nsid'])->count(); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
$this->uniqueUId = new UniqueUid(); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
$nsid = ltrim(rtrim($Student['nsid'],'-'),'-'); |
|
|
|
|
|
|
116
|
|
|
if(!$this->uniqueUId::isValidUniqueId('DBY-898-3J2')){ |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
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..