Skip to content

Commit 2fb2b87

Browse files
committed
feat: migrate code of DatabaseConnectionInformation into own checker
1 parent 9418f33 commit 2fb2b87

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/Components/Health/Checker/HealthChecker/SystemInfoChecker.php

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Frosh\Tools\Components\Health\Checker\CheckerInterface;
88
use Frosh\Tools\Components\Health\HealthCollection;
99
use Frosh\Tools\Components\Health\SettingsResult;
10-
use Shopware\Core\Maintenance\System\Struct\DatabaseConnectionInformation;
10+
use Shopware\Core\DevOps\Environment\EnvironmentHelper;
1111
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1212

1313
class SystemInfoChecker implements HealthCheckerInterface, CheckerInterface
@@ -36,20 +36,44 @@ private function checkPath(HealthCollection $collection): void
3636

3737
private function getDatabaseInfo(HealthCollection $collection): void
3838
{
39-
$databaseConnectionInfo = (new DatabaseConnectionInformation())->fromEnv();
39+
$result = new SettingsResult();
40+
$result->assign([
41+
'id' => 'database-info',
42+
'snippet' => 'Database',
43+
'current' => 'unknown',
44+
]);
4045

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+
}
5478
}
5579
}

0 commit comments

Comments
 (0)