From 771b85eb6c7b22e0b458f632a634208ac4ca981c Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Mon, 12 Jan 2026 22:38:08 +0100 Subject: [PATCH] sdasdsa --- public/page/retool/emailtemplate_bridge.php | 57 ++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/public/page/retool/emailtemplate_bridge.php b/public/page/retool/emailtemplate_bridge.php index da96e29..a9327d7 100644 --- a/public/page/retool/emailtemplate_bridge.php +++ b/public/page/retool/emailtemplate_bridge.php @@ -31,11 +31,62 @@ use App\App; $appConfig = App::get()->config(); $dbConfig = $appConfig->db ?? []; +function bridgeResolveDsn(array $dbConfig): string +{ + $dsn = (string)($dbConfig['dsn'] ?? ''); + if ($dsn !== '') { + return $dsn; + } + + $driver = (string)($dbConfig['driver'] ?? ''); + if ($driver === '') { + return ''; + } + + return match ($driver) { + 'mysql' => (function () use ($dbConfig): string { + $dbname = (string)($dbConfig['dbname'] ?? ''); + if ($dbname === '') { + return ''; + } + $charset = (string)($dbConfig['charset'] ?? 'utf8mb4'); + if (!empty($dbConfig['unix_socket'])) { + return sprintf( + 'mysql:unix_socket=%s;dbname=%s;charset=%s', + (string)$dbConfig['unix_socket'], + $dbname, + $charset + ); + } + $host = (string)($dbConfig['host'] ?? 'localhost'); + $port = (int)($dbConfig['port'] ?? 3306); + return sprintf('mysql:host=%s;port=%d;dbname=%s;charset=%s', $host, $port, $dbname, $charset); + })(), + 'pgsql' => (function () use ($dbConfig): string { + $dbname = (string)($dbConfig['dbname'] ?? ''); + if ($dbname === '') { + return ''; + } + $host = (string)($dbConfig['host'] ?? 'localhost'); + $port = (int)($dbConfig['port'] ?? 5432); + return sprintf('pgsql:host=%s;port=%d;dbname=%s', $host, $port, $dbname); + })(), + 'sqlite' => (function () use ($dbConfig): string { + $path = (string)($dbConfig['path'] ?? ''); + if ($path === '') { + $path = ':memory:'; + } + return 'sqlite:' . $path; + })(), + default => '', + }; +} + // 2) Bridge-spezifische Konfiguration auf Basis der App-Config $bridgeConfig = [ 'token' => getenv('EMAILTEMPLATE_BRIDGE_TOKEN') ?: 'kgIqdL9aNWsFWy6mhSRpnuLc1EbZ62sGCcJAwjjlqqznEGE13szhksWUan0cEdjE', 'db' => [ - 'dsn' => getenv('EMAILTEMPLATE_BRIDGE_DSN') ?: ($dbConfig['dsn'] ?? ''), + 'dsn' => getenv('EMAILTEMPLATE_BRIDGE_DSN') ?: bridgeResolveDsn($dbConfig), 'user' => getenv('EMAILTEMPLATE_BRIDGE_DB_USER') ?: ($dbConfig['user'] ?? ''), 'pass' => getenv('EMAILTEMPLATE_BRIDGE_DB_PASS') ?: ($dbConfig['password'] ?? ''), 'options' => $dbConfig['options'] ?? [ @@ -96,6 +147,10 @@ function bridgeDb(array $config): PDO return $pdo; } + if (empty($config['db']['dsn'])) { + bridgeRespond(['ok' => false, 'error' => 'DB DSN not configured'], 500); + } + try { $pdo = new PDO( $config['db']['dsn'],