asdsad
This commit is contained in:
@@ -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,11 +110,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$payload[$name] = $value;
|
||||
}
|
||||
|
||||
$current = array_replace_recursive($current, $payload);
|
||||
|
||||
$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.';
|
||||
$current = array_replace_recursive($current, $payload);
|
||||
$module = modules()->get($moduleName) ?: $module;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="card">
|
||||
<div class="pill">Setup</div>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user