Skip to content

Commit 2ced182

Browse files
committed
feat: add system check commands for Node.js, MySQL, and environment status
1 parent b9bc5d1 commit 2ced182

File tree

1 file changed

+203
-3
lines changed

1 file changed

+203
-3
lines changed

src/Console/Command/System/CheckCommand.php

Lines changed: 203 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,207 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
105105
return Cli::RETURN_SUCCESS;
106106
}
107107

108-
// ... [Hier folgen die bestehenden privaten Methoden für die Systemchecks]
109-
// Die privaten Hilfsmethoden wurden hier aus Platzgründen weggelassen,
110-
// sollten aber aus der alten Klasse übernommen werden
108+
/**
109+
* Get Node.js version
110+
*
111+
* @return string
112+
*/
113+
private function getNodeVersion(): string
114+
{
115+
exec('node -v 2>/dev/null', $output, $returnCode);
116+
return $returnCode === 0 && !empty($output) ? trim($output[0], 'v') : 'Not installed';
117+
}
118+
119+
/**
120+
* Get latest LTS Node.js version
121+
*
122+
* @return string
123+
*/
124+
private function getLatestLtsNodeVersion(): string
125+
{
126+
try {
127+
$nodeData = file_get_contents(self::NODE_LTS_URL);
128+
if ($nodeData === false) {
129+
return 'Unknown';
130+
}
131+
132+
$nodes = json_decode($nodeData, true);
133+
if (!is_array($nodes)) {
134+
return 'Unknown';
135+
}
136+
137+
foreach ($nodes as $node) {
138+
if (isset($node['lts']) && $node['lts'] !== false) {
139+
return trim($node['version'], 'v');
140+
}
141+
}
142+
return 'Unknown';
143+
} catch (\Exception $e) {
144+
return 'Unknown';
145+
}
146+
}
147+
148+
/**
149+
* Get MySQL version
150+
*
151+
* @return string
152+
*/
153+
private function getShortMysqlVersion(): string
154+
{
155+
exec('mysql --version 2>/dev/null', $output, $returnCode);
156+
if ($returnCode !== 0 || empty($output)) {
157+
return 'Not available';
158+
}
159+
160+
$versionString = $output[0];
161+
preg_match('/Distrib ([0-9.]+)/', $versionString, $matches);
162+
return isset($matches[1]) ? $matches[1] : 'Unknown';
163+
}
164+
165+
/**
166+
* Get database type
167+
*
168+
* @return string
169+
*/
170+
private function getDatabaseType(): string
171+
{
172+
return 'MySQL'; // In der aktuellen Version ist nur MySQL unterstützt
173+
}
174+
175+
/**
176+
* Get OS info
177+
*
178+
* @return string
179+
*/
180+
private function getShortOsInfo(): string
181+
{
182+
return php_uname('s') . ' ' . php_uname('r');
183+
}
184+
185+
/**
186+
* Get Composer version
187+
*
188+
* @return string
189+
*/
190+
private function getComposerVersion(): string
191+
{
192+
exec('composer --version 2>/dev/null', $output, $returnCode);
193+
if ($returnCode !== 0 || empty($output)) {
194+
return 'Not installed';
195+
}
196+
197+
preg_match('/Composer version ([^ ]+)/', $output[0], $matches);
198+
return isset($matches[1]) ? $matches[1] : 'Unknown';
199+
}
200+
201+
/**
202+
* Get NPM version
203+
*
204+
* @return string
205+
*/
206+
private function getNpmVersion(): string
207+
{
208+
exec('npm --version 2>/dev/null', $output, $returnCode);
209+
return $returnCode === 0 && !empty($output) ? trim($output[0]) : 'Not installed';
210+
}
211+
212+
/**
213+
* Get Git version
214+
*
215+
* @return string
216+
*/
217+
private function getGitVersion(): string
218+
{
219+
exec('git --version 2>/dev/null', $output, $returnCode);
220+
if ($returnCode !== 0 || empty($output)) {
221+
return 'Not installed';
222+
}
223+
224+
preg_match('/git version (.+)/', $output[0], $matches);
225+
return isset($matches[1]) ? $matches[1] : 'Unknown';
226+
}
227+
228+
/**
229+
* Get Xdebug status
230+
*
231+
* @return string
232+
*/
233+
private function getXdebugStatus(): string
234+
{
235+
return extension_loaded('xdebug') ? 'Enabled' : 'Disabled';
236+
}
237+
238+
/**
239+
* Get Redis status
240+
*
241+
* @return string
242+
*/
243+
private function getRedisStatus(): string
244+
{
245+
return extension_loaded('redis') ? 'Enabled' : 'Disabled';
246+
}
247+
248+
/**
249+
* Get search engine status
250+
*
251+
* @return string
252+
*/
253+
private function getSearchEngineStatus(): string
254+
{
255+
if (extension_loaded('elasticsearch')) {
256+
return 'Elasticsearch Available';
257+
} elseif (extension_loaded('opensearch')) {
258+
return 'OpenSearch Available';
259+
}
260+
return 'Not Available';
261+
}
262+
263+
/**
264+
* Get important PHP extensions
265+
*
266+
* @return array
267+
*/
268+
private function getImportantPhpExtensions(): array
269+
{
270+
$extensions = [];
271+
$requiredExtensions = [
272+
'curl', 'dom', 'fileinfo', 'gd', 'intl', 'json', 'mbstring',
273+
'openssl', 'pdo_mysql', 'simplexml', 'soap', 'xml', 'zip'
274+
];
275+
276+
foreach ($requiredExtensions as $ext) {
277+
$status = extension_loaded($ext) ? 'Enabled' : 'Disabled';
278+
$extensions[] = [$ext, $status];
279+
}
280+
281+
return $extensions;
282+
}
283+
284+
/**
285+
* Get PHP memory limit
286+
*
287+
* @return string
288+
*/
289+
private function getPhpMemoryLimit(): string
290+
{
291+
return ini_get('memory_limit');
292+
}
293+
294+
/**
295+
* Get disk space
296+
*
297+
* @return string
298+
*/
299+
private function getDiskSpace(): string
300+
{
301+
$totalSpace = disk_total_space('.');
302+
$freeSpace = disk_free_space('.');
303+
304+
$totalGB = round($totalSpace / 1024 / 1024 / 1024, 2);
305+
$freeGB = round($freeSpace / 1024 / 1024 / 1024, 2);
306+
$usedGB = round($totalGB - $freeGB, 2);
307+
$usedPercent = round(($usedGB / $totalGB) * 100, 2);
308+
309+
return "$usedGB GB / $totalGB GB ($usedPercent%)";
310+
}
111311
}

0 commit comments

Comments
 (0)