|
7 | 7 | use Frosh\Tools\Components\Health\Checker\CheckerInterface; |
8 | 8 | use Frosh\Tools\Components\Health\HealthCollection; |
9 | 9 | use Frosh\Tools\Components\Health\SettingsResult; |
10 | | -use Shopware\Core\Maintenance\System\Struct\DatabaseConnectionInformation; |
| 10 | +use Shopware\Core\DevOps\Environment\EnvironmentHelper; |
11 | 11 | use Symfony\Component\DependencyInjection\Attribute\Autowire; |
12 | 12 |
|
13 | 13 | class SystemInfoChecker implements HealthCheckerInterface, CheckerInterface |
@@ -36,20 +36,44 @@ private function checkPath(HealthCollection $collection): void |
36 | 36 |
|
37 | 37 | private function getDatabaseInfo(HealthCollection $collection): void |
38 | 38 | { |
39 | | - $databaseConnectionInfo = (new DatabaseConnectionInformation())->fromEnv(); |
| 39 | + $result = new SettingsResult(); |
| 40 | + $result->assign([ |
| 41 | + 'id' => 'database-info', |
| 42 | + 'snippet' => 'Database', |
| 43 | + 'current' => 'unknown', |
| 44 | + ]); |
40 | 45 |
|
41 | | - $collection->add( |
42 | | - SettingsResult::ok( |
43 | | - 'database-info', |
44 | | - 'Database', |
45 | | - \sprintf( |
46 | | - '%s@%s:%d/%s', |
47 | | - $databaseConnectionInfo->getUsername(), |
48 | | - $databaseConnectionInfo->getHostname(), |
49 | | - $databaseConnectionInfo->getPort(), |
50 | | - $databaseConnectionInfo->getDatabaseName(), |
51 | | - ), |
52 | | - ), |
53 | | - ); |
| 46 | + try { |
| 47 | + $dsn = trim((string) EnvironmentHelper::getVariable('DATABASE_URL', getenv('DATABASE_URL'))); |
| 48 | + if ($dsn === '') { |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + $params = parse_url($dsn); |
| 53 | + if ($params === false) { |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + foreach ($params as $param => $value) { |
| 58 | + if (!\is_string($value)) { |
| 59 | + continue; |
| 60 | + } |
| 61 | + |
| 62 | + $params[$param] = rawurldecode($value); |
| 63 | + } |
| 64 | + |
| 65 | + $path = (string) ($params['path'] ?? '/'); |
| 66 | + $dbName = trim(substr($path, 1)); |
| 67 | + |
| 68 | + $result->current =\sprintf( |
| 69 | + '%s@%s:%d/%s', |
| 70 | + $params['user'] ?? null, |
| 71 | + $params['host'] ?? null, |
| 72 | + (int) ($params['port'] ?? '3306'), |
| 73 | + $dbName, |
| 74 | + ); |
| 75 | + } finally { |
| 76 | + $collection->add($result); |
| 77 | + } |
54 | 78 | } |
55 | 79 | } |
0 commit comments