1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Facades\DB; |
7
|
|
|
use Illuminate\Support\Facades\Log; |
8
|
|
|
use Illuminate\Database\Eloquent\Builder; |
9
|
|
|
|
10
|
|
|
use App\Models\Institution_grade; |
11
|
|
|
use PhpParser\Node\Stmt\TryCatch; |
12
|
|
|
|
13
|
|
|
class RollbackStudentFromInstitutes extends Command |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The name and signature of the console command. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'admission:rollback {institution}'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Rollback promoted flag in institution_grades table to 2019'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Create a new command instance. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
parent::__construct(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the console command. |
41
|
|
|
* |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function handle() |
45
|
|
|
{ |
46
|
|
|
/* |
47
|
|
|
* Set back the promoted flag in institution_grades table to 2019. |
48
|
|
|
* 1. Get all the values of promoted field by each record |
49
|
|
|
* 2. Assign all the records to an array |
50
|
|
|
* 3. Loop through all the indexes of the array and check whether the promoted values are equal to 2019 |
51
|
|
|
* 4. If not, set them to 2019 |
52
|
|
|
*/ |
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
/* |
56
|
|
|
* Getting all the records by corresponding institute_id. |
57
|
|
|
*/ |
58
|
|
|
$this->info('Fetching all the records...'); |
59
|
|
|
$institution_grades = DB::select('select * from institution_grades where institution_id = :id', ['id' => $this->argument('institution')]); |
60
|
|
|
|
61
|
|
|
/* |
62
|
|
|
* First check whether the array is not empty |
63
|
|
|
* Then loop though all the records and check the promoted value |
64
|
|
|
* If the promoted value is equal to 2019 keep it as it is otherwise set it back to 2019 |
65
|
|
|
*/ |
66
|
|
|
if (!empty($institution_grades)) { |
67
|
|
|
|
68
|
|
|
$this->info('Fetched ' . count($institution_grades) . ' records'); |
69
|
|
|
|
70
|
|
|
foreach ($institution_grades as $institute_grade) { |
71
|
|
|
if ($institute_grade->promoted == "2019") { |
72
|
|
|
$this->info('Promoted year have already set to 2019'); |
73
|
|
|
} else { |
74
|
|
|
$this->info('Updating record ======================================='); |
75
|
|
|
DB::update("update institution_grades set promoted ='2019' where institution_id = ?", [$this->argument('institution')]); |
76
|
|
|
$this->info('Record updated ========================================'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} else { |
80
|
|
|
$this->info('No results!'); |
81
|
|
|
} |
82
|
|
|
} catch (\Exception $e) { |
83
|
|
|
return $e->getMessage(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|