Skip to content

Commit 06aa59c

Browse files
author
Thomas Hauschild
committed
refactor system and theme commands
1 parent af0022b commit 06aa59c

9 files changed

+325
-446
lines changed

src/Console/Command/AbstractCommand.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,28 @@
1717
*/
1818
abstract class AbstractCommand extends Command
1919
{
20+
/**
21+
* Default command group prefix
22+
*/
23+
protected const COMMAND_PREFIX = 'mageforge';
24+
2025
/**
2126
* @var SymfonyStyle
2227
*/
2328
protected SymfonyStyle $io;
2429

30+
/**
31+
* Get the command name with proper group structure
32+
*
33+
* @param string $group The command group (e.g. 'theme', 'system')
34+
* @param string $command The specific command (e.g. 'build', 'watch')
35+
* @return string The properly formatted command name
36+
*/
37+
protected function getCommandName(string $group, string $command): string
38+
{
39+
return sprintf('%s:%s:%s', static::COMMAND_PREFIX, $group, $command);
40+
}
41+
2542
/**
2643
* Execute the command
2744
*
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenForgeProject\MageForge\Console\Command\System;
6+
7+
use Composer\Semver\Comparator;
8+
use Magento\Framework\App\ProductMetadataInterface;
9+
use Magento\Framework\Console\Cli;
10+
use Magento\Framework\Escaper;
11+
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
12+
use Symfony\Component\Console\Helper\TableSeparator;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
/**
17+
* Command for checking system information
18+
*/
19+
class CheckCommand extends AbstractCommand
20+
{
21+
private const NODE_LTS_URL = 'https://nodejs.org/dist/index.json';
22+
23+
/**
24+
* @param ProductMetadataInterface $productMetadata
25+
* @param Escaper $escaper
26+
*/
27+
public function __construct(
28+
private readonly ProductMetadataInterface $productMetadata,
29+
private readonly Escaper $escaper,
30+
) {
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected function configure(): void
38+
{
39+
$this->setName($this->getCommandName('system', 'check'))
40+
->setDescription('Displays system information like PHP version and Node.js version');
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function executeCommand(InputInterface $input, OutputInterface $output): int
47+
{
48+
$phpVersion = phpversion();
49+
$nodeVersion = $this->getNodeVersion();
50+
$mysqlVersion = $this->getShortMysqlVersion();
51+
$dbType = $this->getDatabaseType();
52+
$osInfo = $this->getShortOsInfo();
53+
$magentoVersion = $this->productMetadata->getVersion();
54+
$latestLtsNodeVersion = $this->escaper->escapeHtml($this->getLatestLtsNodeVersion());
55+
$composerVersion = $this->getComposerVersion();
56+
$npmVersion = $this->getNpmVersion();
57+
$gitVersion = $this->getGitVersion();
58+
$xdebugStatus = $this->getXdebugStatus();
59+
$redisStatus = $this->getRedisStatus();
60+
$searchEngineStatus = $this->getSearchEngineStatus();
61+
$phpExtensions = $this->getImportantPhpExtensions();
62+
$diskSpace = $this->getDiskSpace();
63+
64+
$nodeVersionDisplay = Comparator::lessThan($nodeVersion, $latestLtsNodeVersion)
65+
? "<fg=yellow>$nodeVersion</> (Latest LTS: <fg=green>$latestLtsNodeVersion</>)"
66+
: "$nodeVersion (Latest LTS: <fg=green>$latestLtsNodeVersion</>)";
67+
68+
$dbDisplay = $dbType . ' ' . $mysqlVersion;
69+
70+
$this->io->section('System Components');
71+
$this->io->table(
72+
['Component', 'Version/Status'],
73+
[
74+
['PHP', $phpVersion . ' (Memory limit: ' . $this->getPhpMemoryLimit() . ')'],
75+
new TableSeparator(),
76+
['Composer', $composerVersion],
77+
new TableSeparator(),
78+
['Node.js', $nodeVersionDisplay],
79+
new TableSeparator(),
80+
['NPM', $npmVersion],
81+
new TableSeparator(),
82+
['Git', $gitVersion],
83+
new TableSeparator(),
84+
['Database', $dbDisplay],
85+
new TableSeparator(),
86+
['Xdebug', $xdebugStatus],
87+
new TableSeparator(),
88+
['Redis', $redisStatus],
89+
new TableSeparator(),
90+
['Search Engine', $searchEngineStatus],
91+
new TableSeparator(),
92+
['OS', $osInfo],
93+
new TableSeparator(),
94+
['Disk Space', $diskSpace],
95+
new TableSeparator(),
96+
['Magento', $magentoVersion]
97+
]
98+
);
99+
100+
if (!empty($phpExtensions)) {
101+
$this->io->section('PHP Extensions');
102+
$this->io->table(['Component', 'Version/Status'], $phpExtensions);
103+
}
104+
105+
return Cli::RETURN_SUCCESS;
106+
}
107+
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
111+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenForgeProject\MageForge\Console\Command\System;
6+
7+
use GuzzleHttp\Client;
8+
use Magento\Framework\Console\Cli;
9+
use Magento\Framework\Filesystem\Driver\File;
10+
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
/**
15+
* Command for displaying version information
16+
*/
17+
class VersionCommand extends AbstractCommand
18+
{
19+
private const API_URL = 'https://api.github.com/repos/openforgeproject/mageforge/releases/latest';
20+
private const PACKAGE_NAME = 'openforgeproject/mageforge';
21+
private const UNKNOWN_VERSION = 'Unknown';
22+
23+
/**
24+
* @param File $fileDriver
25+
*/
26+
public function __construct(
27+
private readonly File $fileDriver
28+
) {
29+
parent::__construct();
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
protected function configure(): void
36+
{
37+
$this->setName($this->getCommandName('system', 'version'))
38+
->setDescription('Displays the module version and the latest version');
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protected function executeCommand(InputInterface $input, OutputInterface $output): int
45+
{
46+
$moduleVersion = $this->getModuleVersion();
47+
$latestVersion = $this->getLatestVersion();
48+
49+
$this->io->title('MageForge Version Information');
50+
$this->io->section('Versions');
51+
$this->io->listing([
52+
"Module Version: $moduleVersion",
53+
"Latest Version: $latestVersion"
54+
]);
55+
56+
return Cli::RETURN_SUCCESS;
57+
}
58+
59+
/**
60+
* Get the current module version
61+
*
62+
* @return string
63+
*/
64+
private function getModuleVersion(): string
65+
{
66+
try {
67+
$composerJson = $this->fileDriver->fileGetContents(
68+
__DIR__ . '/../../../../composer.json'
69+
);
70+
$composerData = json_decode($composerJson, true);
71+
return $composerData['version'] ?? self::UNKNOWN_VERSION;
72+
} catch (\Exception $e) {
73+
return self::UNKNOWN_VERSION;
74+
}
75+
}
76+
77+
/**
78+
* Get the latest version from GitHub
79+
*
80+
* @return string
81+
*/
82+
private function getLatestVersion(): string
83+
{
84+
try {
85+
$client = new Client();
86+
$response = $client->get(self::API_URL, [
87+
'headers' => [
88+
'User-Agent' => 'MageForge-Version-Check'
89+
]
90+
]);
91+
92+
if ($response->getStatusCode() === 200) {
93+
$data = json_decode($response->getBody()->getContents(), true);
94+
return $data['tag_name'] ?? self::UNKNOWN_VERSION;
95+
}
96+
} catch (\Exception $e) {
97+
// Fall through to return unknown
98+
}
99+
100+
return self::UNKNOWN_VERSION;
101+
}
102+
}

0 commit comments

Comments
 (0)