|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Admin\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Models\Babel\ExtensionModel; |
|
7
|
|
|
use Encore\Admin\Layout\Column; |
|
8
|
|
|
use Encore\Admin\Layout\Content; |
|
9
|
|
|
use Encore\Admin\Layout\Row; |
|
10
|
|
|
use Illuminate\Support\Facades\Redirect; |
|
11
|
|
|
use Illuminate\Support\Str; |
|
12
|
|
|
|
|
13
|
|
|
class BabelController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Show the MarketSpace Page. |
|
17
|
|
|
* |
|
18
|
|
|
* @return Response |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
|
|
public function index(Content $content) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
return redirect()->route('admin.babel.installed'); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Show the Installed Page. |
|
27
|
|
|
* |
|
28
|
|
|
* @return Response |
|
29
|
|
|
*/ |
|
30
|
|
|
public function installed(Content $content) |
|
31
|
|
|
{ |
|
32
|
|
|
return $content |
|
|
|
|
|
|
33
|
|
|
->header('Installed Babel Extension') |
|
34
|
|
|
->description('Manage your installed Babel Extension') |
|
35
|
|
|
->row(function(Row $row) { |
|
36
|
|
|
$row->column(12, function(Column $column) { |
|
37
|
|
|
$column->append(Self::installedView()); |
|
38
|
|
|
}); |
|
39
|
|
|
}); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Show the MarketSpace Page. |
|
44
|
|
|
* |
|
45
|
|
|
* @return Response |
|
46
|
|
|
*/ |
|
47
|
|
|
public function marketspace(Content $content) |
|
48
|
|
|
{ |
|
49
|
|
|
return $content |
|
|
|
|
|
|
50
|
|
|
->header('Babel Marketspace') |
|
51
|
|
|
->description('Find extensions from marketspace') |
|
52
|
|
|
->row(function(Row $row) { |
|
53
|
|
|
$row->column(12, function(Column $column) { |
|
54
|
|
|
$column->append(Self::marketspaceView()); |
|
55
|
|
|
}); |
|
56
|
|
|
}); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Show the MarketSpace Detail Page. |
|
61
|
|
|
* |
|
62
|
|
|
* @return Response |
|
63
|
|
|
*/ |
|
64
|
|
|
public function detail($code, Content $content) |
|
65
|
|
|
{ |
|
66
|
|
|
return $content |
|
|
|
|
|
|
67
|
|
|
->header("Extension: $code") |
|
68
|
|
|
->description('Details about this extension') |
|
69
|
|
|
->row(function(Row $row) use ($code) { |
|
70
|
|
|
$row->column(12, function(Column $column) use ($code) { |
|
71
|
|
|
$column->append(Self::marketspaceDetailView($code)); |
|
72
|
|
|
}); |
|
73
|
|
|
}); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Show the Extension Update Page. |
|
78
|
|
|
* |
|
79
|
|
|
* @return Response |
|
80
|
|
|
*/ |
|
81
|
|
|
public function update($extension, Content $content) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->execute('update', $extension, $content); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Show the Extension Install Page. |
|
88
|
|
|
* |
|
89
|
|
|
* @return Response |
|
90
|
|
|
*/ |
|
91
|
|
|
public function install($extension, Content $content) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->execute('install', $extension, $content); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function execute($command, $extension, Content $content) |
|
97
|
|
|
{ |
|
98
|
|
|
return $content |
|
99
|
|
|
->header(Str::title($command)." $extension") |
|
100
|
|
|
->row(function(Row $row) use ($extension) { |
|
101
|
|
|
$row->column(12, function(Column $column) use ($extension) { |
|
102
|
|
|
$column->append(Self::executingView($extension)); |
|
103
|
|
|
}); |
|
104
|
|
|
}); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function updateExtension($extension, Content $content) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->operateExtension('update', $extension, $content); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function installExtension($extension, Content $content) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->operateExtension('install', $extension, $content); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function operateExtension($command, $extension, Content $content) |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
self::executeArtisan("babel:$command $extension --no-interaction"); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
private static function installedView() |
|
123
|
|
|
{ |
|
124
|
|
|
$installedExtensionList=ExtensionModel::localList(); |
|
125
|
|
|
|
|
126
|
|
|
return view('admin::babel.installed', [ |
|
127
|
|
|
'installedExtensionList'=>$installedExtensionList |
|
128
|
|
|
]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
private static function marketspaceView() |
|
132
|
|
|
{ |
|
133
|
|
|
$extensionList=ExtensionModel::list(); |
|
134
|
|
|
|
|
135
|
|
|
if(empty($extensionList)){ |
|
136
|
|
|
return view('admin::babel.empty'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return view('admin::babel.marketspace', [ |
|
140
|
|
|
'extensionList'=>$extensionList |
|
141
|
|
|
]); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
private static function marketspaceDetailView($code) |
|
145
|
|
|
{ |
|
146
|
|
|
$details=ExtensionModel::remoteDetail($code); |
|
147
|
|
|
|
|
148
|
|
|
if(empty($details)){ |
|
149
|
|
|
return view('admin::babel.empty'); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return view('admin::babel.detail', [ |
|
153
|
|
|
'details'=>$details |
|
154
|
|
|
]); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
private static function executingView($extension) |
|
158
|
|
|
{ |
|
159
|
|
|
$details=ExtensionModel::remoteDetail($extension); |
|
160
|
|
|
|
|
161
|
|
|
if(empty($details)){ |
|
162
|
|
|
return view('admin::babel.empty'); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
return view('admin::babel.execute', [ |
|
166
|
|
|
'extension'=>$extension |
|
167
|
|
|
]); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
private static function executeArtisan($command) |
|
171
|
|
|
{ |
|
172
|
|
|
$fp = popen('php "'.base_path('artisan').'" '.$command, "r"); |
|
173
|
|
|
while($b = fgets($fp, 2048)) { |
|
|
|
|
|
|
174
|
|
|
echo str_pad(json_encode([ |
|
175
|
|
|
"ret"=>200, |
|
176
|
|
|
"desc"=>"Succeed", |
|
177
|
|
|
"data"=>[ |
|
178
|
|
|
"message"=>$b |
|
179
|
|
|
] |
|
180
|
|
|
])."\n",4096); |
|
181
|
|
|
@ob_flush(); |
|
|
|
|
|
|
182
|
|
|
flush(); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
pclose($fp); |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|