|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Blacklight\Tmux; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use Ytake\LaravelSmarty\Smarty; |
|
8
|
|
|
use Illuminate\Support\Facades\App; |
|
9
|
|
|
|
|
10
|
|
|
class UpdateNNTmux extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'nntmux:all'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Update NNTmux installation'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \app\extensions\util\Git object. |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $git; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var array Decoded JSON updates file. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $updates = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Create a new command instance. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct() |
|
40
|
|
|
{ |
|
41
|
|
|
parent::__construct(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Execute the console command. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function handle() |
|
48
|
|
|
{ |
|
49
|
|
|
$maintenance = $this->appDown(); |
|
50
|
|
|
$running = $this->stopTmux(); |
|
51
|
|
|
|
|
52
|
|
|
try { |
|
53
|
|
|
$output = $this->call('nntmux:git'); |
|
54
|
|
|
if ($output === 'Already up-to-date.') { |
|
|
|
|
|
|
55
|
|
|
$this->info($output); |
|
56
|
|
|
} else { |
|
57
|
|
|
$status = $this->call('nntmux:composer'); |
|
58
|
|
|
if ($status) { |
|
59
|
|
|
$this->error('Composer failed to update!!'); |
|
60
|
|
|
} |
|
61
|
|
|
$fail = $this->call('nntmux:db'); |
|
62
|
|
|
if ($fail) { |
|
63
|
|
|
$this->error('Db updating failed!!'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} catch (\Exception $e) { |
|
67
|
|
|
$this->error($e->getMessage()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$cleared = (new Smarty())->setCompileDir(config('ytake-laravel-smarty.compile_path'))->clearCompiledTemplate(); |
|
71
|
|
|
if ($cleared) { |
|
72
|
|
|
$this->output->writeln('<comment>The Smarty compiled template cache has been cleaned for you</comment>'); |
|
73
|
|
|
} else { |
|
74
|
|
|
$this->output->writeln( |
|
75
|
|
|
'<comment>You should clear your Smarty compiled template cache at: '. |
|
76
|
|
|
config('ytake-laravel-smarty.compile_path').'</comment>' |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if ($maintenance === true) { |
|
81
|
|
|
$this->appUp(); |
|
82
|
|
|
} |
|
83
|
|
|
if ($running === true) { |
|
84
|
|
|
$this->startTmux(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return bool |
|
90
|
|
|
*/ |
|
91
|
|
|
private function appDown() |
|
92
|
|
|
{ |
|
93
|
|
|
if (App::isDownForMaintenance() === false) { |
|
94
|
|
|
$this->call('down'); |
|
95
|
|
|
return true; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* |
|
103
|
|
|
*/ |
|
104
|
|
|
private function appUp() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->call('up'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return bool |
|
111
|
|
|
*/ |
|
112
|
|
|
private function stopTmux() |
|
113
|
|
|
{ |
|
114
|
|
|
if ((new Tmux())->isRunning() === true) { |
|
115
|
|
|
$this->call('tmux-ui:stop', ['type' => 'true']); |
|
116
|
|
|
return true; |
|
117
|
|
|
} |
|
118
|
|
|
return false; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* |
|
123
|
|
|
*/ |
|
124
|
|
|
private function startTmux() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->call('tmux-ui:start'); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|