|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Academic_period; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use App\Models\Institution_shift; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
use App\Http\Controllers\CloneController; |
|
10
|
|
|
|
|
11
|
|
|
class CloneConfigData extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'clone:config {year} {mode} {max}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Clone configuration data for new year'; |
|
26
|
|
|
|
|
27
|
|
|
protected $start_time; |
|
28
|
|
|
protected $end_time; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Create a new command instance. |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct(); |
|
38
|
|
|
$this->shifts = new Institution_shift(); |
|
|
|
|
|
|
39
|
|
|
$this->academic_period = new Academic_period(); |
|
|
|
|
|
|
40
|
|
|
$this->clone = new CloneController(); |
|
|
|
|
|
|
41
|
|
|
$this->output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Execute the console command. |
|
46
|
|
|
* |
|
47
|
|
|
* @return mixed |
|
48
|
|
|
*/ |
|
49
|
|
|
public function handle() |
|
50
|
|
|
{ |
|
51
|
|
|
DB::statement("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"); |
|
52
|
|
|
$this->start_time = microtime(TRUE); |
|
53
|
|
|
$year = $this->argument('year'); |
|
54
|
|
|
$academicPeriod = $this->academic_period->getAcademicPeriod($year); |
|
55
|
|
|
$mode = $this->argument('mode') == 'AL' ? true : false; |
|
56
|
|
|
$previousAcademicPeriodYear = $academicPeriod->order; |
|
|
|
|
|
|
57
|
|
|
$previousAcademicPeriod = Academic_period::where('order',$previousAcademicPeriodYear+1)->first(); |
|
58
|
|
|
$shift = $this->shifts->getShiftsToClone($previousAcademicPeriod->code,$this->argument(('max')),$mode); |
|
|
|
|
|
|
59
|
|
|
$params = [ |
|
60
|
|
|
'year' => $year, |
|
61
|
|
|
'academic_period' => $academicPeriod, |
|
62
|
|
|
'previous_academic_period' => $previousAcademicPeriod, |
|
63
|
|
|
'mode' => $this->argument('mode') |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
$function = array($this->clone, 'process'); |
|
67
|
|
|
if(count($shift) > 0){ |
|
68
|
|
|
// processParallel($function,$shift, $this->argument('max'),$params); |
|
69
|
|
|
array_walk($shift,$function,$params); |
|
70
|
|
|
}else{ |
|
71
|
|
|
$this->output->writeln('Nothing to clone'); |
|
72
|
|
|
} |
|
73
|
|
|
$this->end_time = microtime(TRUE); |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'); |
|
77
|
|
|
$this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete'); |
|
78
|
|
|
$this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|