1 | <?php |
||
16 | class OptimiseCommand extends Command |
||
17 | { |
||
18 | const BACKGROUND_MOD_MEX = 'background mode'; |
||
19 | const BACKGROUND_COMPLETED_MEX = 'All background tasks started'; |
||
20 | /** |
||
21 | * The name and signature of the console command. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $signature = 'optimise:meetings {companyId?} {--background}'; |
||
26 | |||
27 | /** |
||
28 | * The console command description. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $description = 'Optimise meetings'; |
||
33 | |||
34 | /** |
||
35 | * @var Schedule laravel schedule object needed to perform command in background |
||
36 | */ |
||
37 | private $schedule; |
||
38 | |||
39 | /** |
||
40 | * Create a new command instance. |
||
41 | * @param Schedule $schedule |
||
42 | * |
||
43 | */ |
||
44 | 12 | public function __construct(Schedule $schedule) |
|
49 | |||
50 | /** |
||
51 | * Execute the console command. |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 3 | public function handle() |
|
56 | { |
||
57 | // |
||
58 | //TODO insert a timeout |
||
59 | //TODO try...catch with destruct |
||
60 | 3 | $companyId = $this->argument('companyId'); |
|
61 | 3 | if (is_numeric($companyId)) |
|
62 | 3 | $this->makeForeground(Company::findOrFail($companyId)); |
|
63 | else |
||
64 | $this->syncAll(); |
||
65 | 3 | } |
|
66 | |||
67 | /** |
||
68 | * optimise company foreground |
||
69 | * @param Company $company |
||
70 | */ |
||
71 | 3 | private function makeForeground(Company $company) |
|
72 | { |
||
73 | 3 | $this->info('Optimisation company ' . $company->id . ' started'); |
|
74 | 3 | (new Optimise($company, $this->schedule, $this->laravel))->optimise()->save(); |
|
75 | 3 | $this->info('Optimisation ' . $company->id . ' completed'); |
|
76 | 3 | } |
|
77 | |||
78 | private function syncAll() |
||
92 | |||
93 | /** |
||
94 | * optimise company via exec command |
||
95 | * @param Company $company |
||
96 | */ |
||
97 | private function makeBackground(Company $company) |
||
103 | } |
||
104 |