fix: inline getDatabasePath into Database.php, delete config/config.php

- 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
This commit is contained in:
Pontoporeia
2026-04-20 14:23:30 +02:00
parent 468278349a
commit fa75ca4a65
4 changed files with 16 additions and 58 deletions

View File

@@ -1,7 +1,5 @@
<?php
require_once __DIR__ . '/../../config/config.php';
/**
* Unified Database connection class for Post-ERG thesis database
* Combines functionality from both front-backend and formulaire
@@ -36,18 +34,25 @@ class Database {
}
/**
* Determine database path
* Uses centralized config from config.php
* Priority: custom path > 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;
}
/**