mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user