From fa75ca4a65f453574ce73d36d7434e88764c1b43 Mon Sep 17 00:00:00 2001 From: Pontoporeia Date: Mon, 20 Apr 2026 14:23:30 +0200 Subject: [PATCH] fix: inline getDatabasePath into Database.php, delete config/config.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove require_once for config/config.php (file was never deployed — outside app/) - Inline DB path resolution directly in Database::determineDatabasePath() - Uses APP_ROOT when defined (bootstrap already loaded), falls back to __DIR__/../ - DB_ENV=test|prod env-var override preserved for tests - php -S cli-server -> test.db, nginx/fpm -> posterg.db --- TODO.md | 2 ++ app/src/Database.php | 23 ++++++++++++-------- app/storage/test.db | Bin 270336 -> 270336 bytes config/config.php | 49 ------------------------------------------- 4 files changed, 16 insertions(+), 58 deletions(-) delete mode 100644 config/config.php diff --git a/TODO.md b/TODO.md index fb749aa..fa3c6b0 100644 --- a/TODO.md +++ b/TODO.md @@ -57,6 +57,8 @@ - [x] Update Dispatcher to render full pages (head + header + view + footer) instead of requiring bootstrap - [x] Ensure admin/index.php bootstraps its own path (not affected by front controller) +- [x] Fix config/config.php path mess — inline getDatabasePath() into Database.php, delete config/config.php + ### Phase 3: Server config - [ ] Update router.php — route all PHP requests to Dispatcher - [ ] Update nginx config — point all public routes to index.php via try_files diff --git a/app/src/Database.php b/app/src/Database.php index 9b74da2..bc604f4 100644 --- a/app/src/Database.php +++ b/app/src/Database.php @@ -1,7 +1,5 @@ config.php settings + * Determine database path. + * Priority: explicit override → DB_ENV env-var → sapi auto-detect. + * APP_ROOT is defined by bootstrap.php before any controller loads Database. */ - private function determineDatabasePath($customPath = null) { - // Allow explicit override + private function determineDatabasePath($customPath = null): string { if ($customPath !== null && file_exists($customPath)) { return $customPath; } - // Use centralized configuration - return getDatabasePath(); + $root = defined('APP_ROOT') ? APP_ROOT : __DIR__ . '/..'; + $testDb = $root . '/storage/test.db'; + $prodDb = $root . '/storage/posterg.db'; + + $env = getenv('DB_ENV'); + if ($env === 'test') return $testDb; + if ($env === 'prod') return $prodDb; + + // php -S (dev server) → test DB; everything else (nginx/fpm) → prod DB + return php_sapi_name() === 'cli-server' ? $testDb : $prodDb; } /** diff --git a/app/storage/test.db b/app/storage/test.db index b66f21a33f3e1a1dc9d4686bcb621193c8fb6b24..6215a6b01b8d4977fa52ea247ccec3afa421eed5 100644 GIT binary patch delta 856 zcmZuw!D`z;5VbA)&=6rar$Pu>_L7TYB-yfM9YYU=HqbV?6awm6TE|PJU7=lt7-M9E zp@;rNPyK=R1A6Kgz zdaNIOf8MI=`3J3Wyg00fOn&kiABibeLXil2-GOD9J;!ui(=_lXr4)OXV|P1!r*AoK z*T9*iA@({Qx7TwAoxW}L44ecCd%eMo{dw_aQLQzO7I8fpCu`~(no1@(_ORP_+732w zE=j^54kC6cX$l1Z#xxe`#E)3afDK!=dk$!pM1q8VOl|?Q3nURzt>dx+Qa-(<0pvTT z#HESlezkG(c~X}Xsc7s=MN}rIm|rsvJkuOUWJqD$HDcgZ1@?FrMFtM3BCJTuv4