1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use JeroenNoten\LaravelAdminLte\Http\Helpers\CommandHelper; |
7
|
|
|
|
8
|
|
|
class AdminLteStatusCommand extends Command |
9
|
|
|
{ |
10
|
|
|
protected $signature = 'adminlte:status '. |
11
|
|
|
'{--include-images : Includes AdminLTE asset images to the checkup}'; |
12
|
|
|
|
13
|
|
|
protected $description = 'Checks the install status for AdminLTE assets, routes & views.'; |
14
|
|
|
|
15
|
|
|
protected $extra_steps = [ |
16
|
|
|
'config', 'translations', 'main_views', 'auth_views', 'basic_views', |
17
|
|
|
'basic_routes', |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Execute the console command. |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
public function handle() |
26
|
|
|
{ |
27
|
|
|
$headers = ['Group', 'Assets Name', 'Status', 'Required']; |
28
|
|
|
$step_count = 5; |
29
|
|
|
$table_content = []; |
30
|
|
|
$install_command = new AdminLteInstallCommand(); |
31
|
|
|
|
32
|
|
|
$assets = $install_command->getProtected('assets'); |
33
|
|
|
$package_path = $install_command->getProtected('package_path'); |
34
|
|
|
|
35
|
|
|
$this->line('Checking Installation ...'); |
36
|
|
|
$bar = $this->output->createProgressBar($step_count); |
37
|
|
|
$bar->start(); |
38
|
|
|
|
39
|
|
|
// Checking Assets |
40
|
|
|
foreach ($assets as $asset_key => $asset) { |
41
|
|
|
$table_content[] = ['assets', $asset['name'], $this->resolveCompare($this->checkAsset($asset_key, $this->option('include-images'))), 'true']; |
42
|
|
|
} |
43
|
|
|
$bar->advance(); |
44
|
|
|
|
45
|
|
|
// Checking Config |
46
|
|
|
$table_content[] = ['config', 'Default Config', $this->resolveCompare($this->compareFile($package_path.'config/adminlte.php', base_path('config/adminlte.php'))), 'true']; |
|
|
|
|
47
|
|
|
$bar->advance(); |
48
|
|
|
|
49
|
|
|
// Checking Translations |
50
|
|
|
$table_content[] = ['translations', 'Default Translations', $this->resolveCompare($this->compareFolder('resources/lang', 'resources/lang', $package_path, base_path(), true, ['menu.php'])), 'true']; |
51
|
|
|
$bar->advance(); |
52
|
|
|
|
53
|
|
|
// Checking Main Views |
54
|
|
|
$table_content[] = ['auth_views', 'Auth Views', $this->resolveCompare($this->compareAuthViews()), 'false']; |
55
|
|
|
$bar->advance(); |
56
|
|
|
|
57
|
|
|
// Checking Main Views |
58
|
|
|
$table_content[] = ['main_views', 'Main Views', $this->resolveCompare($this->compareFolder('resources/views', 'resources/views/vendor/adminlte/', $package_path, base_path(), true)), 'false']; |
59
|
|
|
$bar->advance(); |
60
|
|
|
|
61
|
|
|
$bar->finish(); |
62
|
|
|
|
63
|
|
|
$this->line(''); |
64
|
|
|
$this->line('Installation Checked'); |
65
|
|
|
|
66
|
|
|
$this->table($headers, $table_content); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Resolve Compare. |
71
|
|
|
* |
72
|
|
|
* @param $compare |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
protected function resolveCompare($compare) |
76
|
|
|
{ |
77
|
|
|
if ($compare === 1) { |
78
|
|
|
return 'Installed'; |
79
|
|
|
} elseif ($compare === 2) { |
80
|
|
|
return 'Update Available / Modified'; |
81
|
|
|
} elseif ($compare === 0) { |
82
|
|
|
return 'Not Installed'; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Check Plugin. |
88
|
|
|
* |
89
|
|
|
* @param $asset_key |
90
|
|
|
* @param $include_images |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
protected function checkAsset($asset_key, $include_images) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$install_command = new AdminLteInstallCommand(); |
96
|
|
|
$asset = $install_command->getProtected('assets')[$asset_key]; |
97
|
|
|
$assets_path = $install_command->getProtected('assets_path'); |
98
|
|
|
$package_path = $install_command->getProtected('assets_package_path'); |
99
|
|
|
$compare = $compare_multiple = null; |
100
|
|
|
|
101
|
|
|
if (is_array($asset['package_path'])) { |
102
|
|
|
foreach ($asset['package_path'] as $key => $value) { |
103
|
|
|
$compare_multiple += $this->compareFolder($asset['package_path'][$key], $asset['assets_path'][$key], base_path($package_path), public_path($assets_path), $asset['recursive'] ?? true, $asset['ignore'] ?? [], $asset['ignore_ending'] ?? [], $asset['images'] ?? null, $asset['images_path'] ?? null); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$compare_multiple /= count($asset['package_path']); |
107
|
|
|
if ($compare_multiple == 1) { |
|
|
|
|
108
|
|
|
$compare = 1; |
109
|
|
|
} elseif ($compare_multiple >= 1) { |
110
|
|
|
$compare = 2; |
111
|
|
|
} elseif ($compare_multiple <= 1) { |
112
|
|
|
$compare = 0; |
113
|
|
|
} |
114
|
|
|
} else { |
115
|
|
|
$compare = $this->compareFolder($asset['package_path'], $asset['assets_path'], base_path($package_path), public_path($assets_path), $asset['recursive'] ?? true, $asset['ignore'] ?? [], $asset['ignore_ending'] ?? [], $asset['images'] ?? null, $asset['images_path'] ?? null); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $compare; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Compare Folder. |
123
|
|
|
* |
124
|
|
|
* @param $source_path |
125
|
|
|
* @param $destination_path |
126
|
|
|
* @param $source_base_path |
127
|
|
|
* @param $destination_base_path |
128
|
|
|
* @param $recursive |
129
|
|
|
* @param $ignore |
130
|
|
|
* @param $ignore_ending |
131
|
|
|
* @param $images |
132
|
|
|
* @param $images_path |
133
|
|
|
* @return int |
134
|
|
|
*/ |
135
|
|
|
public function compareFolder($source_path, $destination_path, $source_base_path = null, $destination_base_path = null, $recursive = true, $ignore = [], $ignore_ending = [], $images = null, $images_path = null, $ignore_base_folder = null) |
136
|
|
|
{ |
137
|
|
|
$dest_exist = true; |
138
|
|
|
$dest_missing = false; |
139
|
|
|
$dest_missmatch = false; |
140
|
|
|
$dest_child_exist = true; |
141
|
|
|
$dest_child_missmatch = false; |
142
|
|
|
|
143
|
|
|
if (! $source_base_path) { |
144
|
|
|
$source_base_path = base_path(); |
145
|
|
|
} |
146
|
|
|
if (substr($source_base_path, -1) !== '/') { |
147
|
|
|
$source_base_path .= '/'; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if (! $destination_base_path) { |
151
|
|
|
$destination_base_path = public_path(); |
152
|
|
|
} |
153
|
|
|
if (substr($destination_base_path, -1) !== '/') { |
154
|
|
|
$destination_base_path .= '/'; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if (is_array($source_path)) { |
158
|
|
|
foreach ($source_path as $key => $destination_child_path) { |
159
|
|
|
if (! file_exists($destination_base_path.$destination_child_path)) { |
160
|
|
|
$dest_exist = false; |
161
|
|
|
$dest_child_exist = false; |
162
|
|
|
} else { |
163
|
|
|
$compare = CommandHelper::compareDirectories($source_base_path.$source_path[$key], $destination_base_path.$destination_child_path, '', $ignore, $ignore_ending, $recursive); |
|
|
|
|
164
|
|
|
|
165
|
|
|
if (! $dest_child_missmatch && $compare) { |
166
|
|
|
$dest_child_missmatch = false; |
167
|
|
|
} else { |
168
|
|
|
$dest_child_missmatch = true; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} else { |
173
|
|
|
if (! file_exists($destination_base_path.$destination_path)) { |
174
|
|
|
$dest_exist = false; |
175
|
|
|
} else { |
176
|
|
|
$compare = CommandHelper::compareDirectories($source_base_path.$source_path, $destination_base_path.$destination_path, '', $ignore, $ignore_ending, $recursive, null, true); |
|
|
|
|
177
|
|
|
if ($compare === false) { |
178
|
|
|
$dest_missmatch = true; |
179
|
|
|
} elseif ($compare === null) { |
|
|
|
|
180
|
|
|
$dest_missing = true; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if ($images_path && $images) { |
186
|
|
|
$asset_images_path = $images_path; |
|
|
|
|
187
|
|
|
|
188
|
|
|
foreach ($images as $image_destination_path => $image_asset_path) { |
189
|
|
|
$compareFile = $this->compareFile($source_base_path.$image_destination_path, $destination_base_path.$images_path.$image_asset_path); |
190
|
|
|
if ($compareFile === 0) { |
191
|
|
|
$dest_child_exist = false; |
192
|
|
|
} elseif ($compareFile == 1) { |
193
|
|
|
$dest_child_missmatch = false; |
194
|
|
|
} elseif ($compareFile == 2) { |
195
|
|
|
$dest_child_missmatch = true; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
if ($dest_exist && $dest_child_exist && ! $ignore_base_folder && (! $dest_missmatch && ! $dest_child_missmatch) && ! $dest_missing) { |
201
|
|
|
return 1; |
202
|
|
|
} elseif ($dest_exist && (($dest_missmatch || $dest_child_missmatch) || ! $dest_child_exist)) { |
203
|
|
|
return 2; |
204
|
|
|
} elseif (! $dest_exist || $dest_missing) { |
205
|
|
|
return 0; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Compare File. |
211
|
|
|
* |
212
|
|
|
* @param $source_file |
213
|
|
|
* @param $destination_file |
214
|
|
|
* @return int |
215
|
|
|
*/ |
216
|
|
|
public function compareFile($source_file, $destination_file) |
217
|
|
|
{ |
218
|
|
|
$file_exist = true; |
219
|
|
|
$file_missmatch = false; |
220
|
|
|
|
221
|
|
|
if (! file_exists($destination_file)) { |
222
|
|
|
$file_exist = false; |
223
|
|
|
} else { |
224
|
|
|
$compare = sha1_file($source_file) === sha1_file($destination_file); |
225
|
|
|
if (! $compare) { |
226
|
|
|
$file_missmatch = true; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
if ($file_exist && (! $file_missmatch)) { |
231
|
|
|
return 1; |
232
|
|
|
} elseif ($file_exist && $file_missmatch) { |
233
|
|
|
return 2; |
234
|
|
|
} elseif (! $file_exist) { |
235
|
|
|
return 0; |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Compare Auth Views. |
241
|
|
|
* |
242
|
|
|
* @return int |
243
|
|
|
*/ |
244
|
|
|
public function compareAuthViews() |
245
|
|
|
{ |
246
|
|
|
$install_command = new AdminLteInstallCommand(); |
247
|
|
|
$auth_views = $install_command->getProtected('authViews'); |
248
|
|
|
$view_exists = true; |
|
|
|
|
249
|
|
|
$view_found = 0; |
250
|
|
|
$view_excepted = count($auth_views); |
251
|
|
|
|
252
|
|
|
foreach ($auth_views as $file_name => $file_content) { |
253
|
|
|
$file = $install_command->getViewPath($file_name); |
254
|
|
|
if (file_exists($file)) { |
255
|
|
|
$dest_file_content = file_get_contents($file); |
256
|
|
|
if (strpos($dest_file_content, $file_content) !== false) { |
257
|
|
|
$view_found++; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
if ($view_found === 0) { |
263
|
|
|
return 0; |
264
|
|
|
} elseif ($view_found === $view_excepted) { |
265
|
|
|
return 1; |
266
|
|
|
} elseif ($view_found !== $view_excepted) { |
267
|
|
|
return 2; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|