asdsad
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-15 00:56:09 +02:00
parent 93c867040e
commit 5677a8d806

View File

@@ -59,6 +59,24 @@ $getNested = function (array $source, string $path): mixed {
return $node;
};
$dbGroups = [];
foreach ($fields as $field) {
$name = (string)($field['name'] ?? '');
if (!str_contains($name, '.')) {
continue;
}
[$group, $key] = explode('.', $name, 2);
if ($key !== 'driver') {
continue;
}
$label = (string)($field['label'] ?? $group);
$label = trim(preg_replace('/\s+DB\s+Driver$/i', ' DB', $label) ?? $label);
$label = $label !== '' ? $label : $group;
$dbGroups[$group] = $label;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$payload = [];
@@ -92,10 +110,36 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$payload[$name] = $value;
}
modules()->saveSettings($moduleName, $payload);
$notice = 'Setup gespeichert.';
$current = array_replace_recursive($current, $payload);
$module = modules()->get($moduleName) ?: $module;
$testGroup = (string)($_POST['test_db'] ?? '');
if ($testGroup !== '') {
if (!array_key_exists($testGroup, $dbGroups)) {
$error = 'Unbekannte Datenbank-Konfiguration.';
} else {
$dbConfig = $getNested($current, $testGroup);
if (!is_array($dbConfig)) {
$error = 'Datenbank-Konfiguration ist unvollstaendig.';
} else {
try {
$dbConfig['options'] = array_replace([
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
], (array)($dbConfig['options'] ?? []));
$testPdo = \App\Database::createFromArray($dbConfig);
$testPdo->query('SELECT 1')->fetchColumn();
$notice = $dbGroups[$testGroup] . ': Verbindung erfolgreich.';
} catch (\Throwable $e) {
$error = $dbGroups[$testGroup] . ': Verbindung fehlgeschlagen. ' . $e->getMessage();
}
}
}
} else {
modules()->saveSettings($moduleName, $payload);
$notice = 'Setup gespeichert.';
$module = modules()->get($moduleName) ?: $module;
}
}
?>
<div class="card">
@@ -147,6 +191,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</label>
<?php endforeach; ?>
<?php if ($dbGroups !== []): ?>
<div class="card" style="padding:14px; background:var(--panel-2); display:grid; gap:10px;">
<strong>Datenbankverbindungen testen</strong>
<small class="muted">Der Test nutzt die aktuell eingetragenen Werte aus diesem Formular und speichert sie nicht.</small>
<div style="display:flex; gap:10px; flex-wrap:wrap;">
<?php foreach ($dbGroups as $group => $label): ?>
<button class="nav-link" type="submit" name="test_db" value="<?= e($group) ?>" formnovalidate>
<?= e($label) ?> testen
</button>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div style="display:flex; gap:10px;">
<button class="cta-button" type="submit">Speichern</button>
<a class="nav-link" href="/modules/access/<?= e($moduleName) ?>">Zugriff verwalten</a>