1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Flextype\Plugin\Admin\Controllers; |
6
|
|
|
|
7
|
|
|
use FilesystemIterator; |
8
|
|
|
use Flextype\Component\Number\Number; |
9
|
|
|
use Flextype\Component\Filesystem\Filesystem; |
10
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
|
12
|
|
|
use RecursiveDirectoryIterator; |
13
|
|
|
use RecursiveIteratorIterator; |
14
|
|
|
use function array_merge; |
15
|
|
|
use function file_exists; |
16
|
|
|
use function Flextype\Component\I18n\__; |
|
|
|
|
17
|
|
|
use function getenv; |
18
|
|
|
use function is_array; |
19
|
|
|
use function php_sapi_name; |
20
|
|
|
use function php_uname; |
21
|
|
|
use function realpath; |
22
|
|
|
|
23
|
|
|
class ToolsController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* __construct |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Index page |
35
|
|
|
* |
36
|
|
|
* @param Request $request PSR7 request |
37
|
|
|
* @param Response $response PSR7 response |
38
|
|
|
*/ |
39
|
|
|
public function index(Request $request, Response $response) : Response |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
return $response->withRedirect(flextype('router')->pathFor('admin.tools.information')); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Information page |
46
|
|
|
* |
47
|
|
|
* @param Request $request PSR7 request |
48
|
|
|
* @param Response $response PSR7 response |
49
|
|
|
*/ |
50
|
|
|
public function information(Request $request, Response $response) : Response |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
return flextype('twig')->render( |
|
|
|
|
53
|
|
|
$response, |
54
|
|
|
'plugins/admin/templates/system/tools/information.html', |
55
|
|
|
[ |
56
|
|
|
'menu_item' => 'tools', |
57
|
|
|
'php_uname' => php_uname(), |
58
|
|
|
'webserver' => $_SERVER['SERVER_SOFTWARE'] ?? @getenv('SERVER_SOFTWARE'), |
59
|
|
|
'php_sapi_name' => php_sapi_name(), |
60
|
|
|
'links' => [ |
61
|
|
|
'information' => [ |
62
|
|
|
'link' => flextype('router')->pathFor('admin.tools.index'), |
63
|
|
|
'title' => __('admin_information'), |
|
|
|
|
64
|
|
|
'active' => true |
65
|
|
|
], |
66
|
|
|
'cache' => [ |
67
|
|
|
'link' => flextype('router')->pathFor('admin.tools.cache'), |
68
|
|
|
'title' => __('admin_cache'), |
69
|
|
|
|
70
|
|
|
], |
71
|
|
|
'registry' => [ |
72
|
|
|
'link' => flextype('router')->pathFor('admin.tools.registry'), |
73
|
|
|
'title' => __('admin_registry'), |
74
|
|
|
|
75
|
|
|
], |
76
|
|
|
], |
77
|
|
|
] |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Cache page |
83
|
|
|
* |
84
|
|
|
* @param Request $request PSR7 request |
85
|
|
|
* @param Response $response PSR7 response |
86
|
|
|
*/ |
87
|
|
|
public function cache(Request $request, Response $response) : Response |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
return flextype('twig')->render( |
|
|
|
|
90
|
|
|
$response, |
91
|
|
|
'plugins/admin/templates/system/tools/cache.html', |
92
|
|
|
[ |
93
|
|
|
'menu_item' => 'tools', |
94
|
|
|
'data_size' => Number::byteFormat($this->getDirectorySize(PATH['tmp'] . '/data')), |
|
|
|
|
95
|
|
|
'glide_size' => Number::byteFormat($this->getDirectorySize(PATH['tmp'] . '/glide')), |
96
|
|
|
'twig_size' => Number::byteFormat($this->getDirectorySize(PATH['tmp'] . '/twig')), |
97
|
|
|
'preflight_size' => Number::byteFormat($this->getDirectorySize(PATH['tmp'] . '/preflight')), |
98
|
|
|
'links' => [ |
99
|
|
|
'information' => [ |
100
|
|
|
'link' => flextype('router')->pathFor('admin.tools.index'), |
101
|
|
|
'title' => __('admin_information'), |
|
|
|
|
102
|
|
|
|
103
|
|
|
], |
104
|
|
|
'cache' => [ |
105
|
|
|
'link' => flextype('router')->pathFor('admin.tools.cache'), |
106
|
|
|
'title' => __('admin_cache'), |
107
|
|
|
'active' => true |
108
|
|
|
], |
109
|
|
|
'registry' => [ |
110
|
|
|
'link' => flextype('router')->pathFor('admin.tools.registry'), |
111
|
|
|
'title' => __('admin_registry'), |
112
|
|
|
|
113
|
|
|
], |
114
|
|
|
], |
115
|
|
|
'buttons' => [ |
116
|
|
|
'tools_clear_cache' => [ |
117
|
|
|
'type' => 'action', |
118
|
|
|
'id' => 'clear-cache-all', |
119
|
|
|
'link' => flextype('router')->pathFor('admin.tools.clearCacheAllProcess'), |
120
|
|
|
'title' => __('admin_clear_cache_all'), |
121
|
|
|
], |
122
|
|
|
], |
123
|
|
|
] |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Information page |
129
|
|
|
* |
130
|
|
|
* @param Request $request PSR7 request |
131
|
|
|
* @param Response $response PSR7 response |
132
|
|
|
*/ |
133
|
|
|
public function registry(Request $request, Response $response) : Response |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
return flextype('twig')->render( |
|
|
|
|
136
|
|
|
$response, |
137
|
|
|
'plugins/admin/templates/system/tools/registry.html', |
138
|
|
|
[ |
139
|
|
|
'menu_item' => 'tools', |
140
|
|
|
'registry_dump' => $this->dotArray(flextype('registry')->all()), |
141
|
|
|
'links' => [ |
142
|
|
|
'information' => [ |
143
|
|
|
'link' => flextype('router')->pathFor('admin.tools.index'), |
144
|
|
|
'title' => __('admin_information'), |
|
|
|
|
145
|
|
|
|
146
|
|
|
], |
147
|
|
|
'cache' => [ |
148
|
|
|
'link' => flextype('router')->pathFor('admin.tools.cache'), |
149
|
|
|
'title' => __('admin_cache'), |
150
|
|
|
|
151
|
|
|
], |
152
|
|
|
'registry' => [ |
153
|
|
|
'link' => flextype('router')->pathFor('admin.tools.registry'), |
154
|
|
|
'title' => __('admin_registry'), |
155
|
|
|
'active' => true |
156
|
|
|
], |
157
|
|
|
], |
158
|
|
|
] |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Clear cache process |
164
|
|
|
* |
165
|
|
|
* @param Request $request PSR7 request |
166
|
|
|
* @param Response $response PSR7 response |
167
|
|
|
*/ |
168
|
|
|
public function clearCacheProcess(Request $request, Response $response) : Response |
169
|
|
|
{ |
170
|
|
|
$id = $request->getParsedBody()['cache-id']; |
171
|
|
|
|
172
|
|
|
if ($id == 'data') { |
173
|
|
|
Filesystem::deleteDir(PATH['tmp'] . '/data'); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
if ($id == 'twig') { |
177
|
|
|
Filesystem::deleteDir(PATH['tmp'] . '/twig'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
if ($id == 'glide') { |
181
|
|
|
Filesystem::deleteDir(PATH['tmp'] . '/glide'); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if ($id == 'preflight') { |
185
|
|
|
Filesystem::deleteDir(PATH['tmp'] . '/preflight'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
flextype('flash')->addMessage('success', __('admin_message_cache_files_deleted')); |
|
|
|
|
189
|
|
|
|
190
|
|
|
return $response->withRedirect(flextype('router')->pathFor('admin.tools.cache')); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Clear all cache process |
195
|
|
|
* |
196
|
|
|
* @param Request $request PSR7 request |
197
|
|
|
* @param Response $response PSR7 response |
198
|
|
|
*/ |
199
|
|
|
public function clearCacheAllProcess(Request $request, Response $response) : Response |
|
|
|
|
200
|
|
|
{ |
201
|
|
|
Filesystem::deleteDir(ROOT_DIR . '/var'); |
|
|
|
|
202
|
|
|
|
203
|
|
|
flextype('flash')->addMessage('success', __('admin_message_cache_files_deleted')); |
|
|
|
|
204
|
|
|
|
205
|
|
|
return $response->withRedirect(flextype('router')->pathFor('admin.tools.cache')); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* _dotArray |
210
|
|
|
*/ |
211
|
|
|
private function dotArray($array, $prepend = '') : array |
212
|
|
|
{ |
213
|
|
|
$results = []; |
214
|
|
|
|
215
|
|
|
foreach ($array as $key => $value) { |
216
|
|
|
if (is_array($value) && ! empty($value)) { |
217
|
|
|
$results = array_merge($results, $this->dotArray($value, $prepend . $key . '.')); |
218
|
|
|
} else { |
219
|
|
|
$results[$prepend . $key] = $value; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return $results; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* _getDirectorySize |
228
|
|
|
*/ |
229
|
|
|
private function getDirectorySize($path) |
230
|
|
|
{ |
231
|
|
|
$bytestotal = 0; |
232
|
|
|
$path = realpath($path); |
233
|
|
|
if ($path!==false && $path!=='' && file_exists($path)) { |
234
|
|
|
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { |
235
|
|
|
$bytestotal += $object->getSize(); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
return $bytestotal; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths