diff --git a/partials/landingpages/modules/setup.php b/partials/landingpages/modules/setup.php index da689c6..771f790 100644 --- a/partials/landingpages/modules/setup.php +++ b/partials/landingpages/modules/setup.php @@ -3,6 +3,8 @@ $moduleName = (string)($_GET['module'] ?? ''); $module = modules()->get($moduleName); $error = null; $notice = null; +$testGroup = null; +$dbTestMessages = []; require_admin(); @@ -176,14 +178,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $current = array_replace_recursive($current, $payload); - $testGroup = (string)($_POST['test_db'] ?? ''); - if ($testGroup !== '') { - if (!array_key_exists($testGroup, $dbGroups)) { + $postedTestGroup = (string)($_POST['test_db'] ?? ''); + if ($postedTestGroup !== '') { + $testGroup = $postedTestGroup; + if (!array_key_exists($postedTestGroup, $dbGroups)) { $error = 'Unbekannte Datenbank-Konfiguration.'; } else { - $dbConfig = $getNested($current, $testGroup); + $dbConfig = $getNested($current, $postedTestGroup); if (!is_array($dbConfig)) { - $error = 'Datenbank-Konfiguration ist unvollstaendig.'; + $dbTestMessages[$postedTestGroup] = [ + 'type' => 'error', + 'text' => 'Datenbank-Konfiguration ist unvollstaendig.', + ]; } else { try { $dbConfig['options'] = array_replace([ @@ -193,9 +199,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $testPdo = \App\Database::createFromArray($dbConfig); $testPdo->query('SELECT 1')->fetchColumn(); - $notice = $dbGroups[$testGroup] . ': Verbindung erfolgreich.'; + $dbTestMessages[$postedTestGroup] = [ + 'type' => 'success', + 'text' => 'Verbindung erfolgreich.', + ]; } catch (\Throwable $e) { - $error = $dbGroups[$testGroup] . ': Verbindung fehlgeschlagen. ' . $e->getMessage(); + $dbTestMessages[$postedTestGroup] = [ + 'type' => 'error', + 'text' => 'Verbindung fehlgeschlagen. ' . $e->getMessage(), + ]; } } } @@ -205,6 +217,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $module = modules()->get($moduleName) ?: $module; } } + +$activeDbGroup = $testGroup !== null && array_key_exists($testGroup, $dbGroups) + ? $testGroup + : (array_key_first($dbGroups) ?? ''); ?>