mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +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:
2
TODO.md
2
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Configuration for Post-ERG thesis database
|
||||
* Central location for database paths and environment settings
|
||||
*/
|
||||
|
||||
// Database paths relative to repository root
|
||||
define('DB_ROOT', __DIR__ . '/..');
|
||||
|
||||
// Local dev database (php -S, never committed)
|
||||
define('DB_TEST_PATH', DB_ROOT . '/app/storage/test.db');
|
||||
|
||||
// Production database (nginx/php-fpm on server)
|
||||
define('DB_PROD_PATH', DB_ROOT . '/app/storage/posterg.db');
|
||||
|
||||
/**
|
||||
* Determine which database to use.
|
||||
*
|
||||
* - php built-in server (php -S …) → storage/test.db (local dev)
|
||||
* - everything else (nginx/fpm) → storage/posterg.db (production)
|
||||
*
|
||||
* The DB_ENV env-var can still override either way:
|
||||
* DB_ENV=test → force test.db
|
||||
* DB_ENV=prod → force posterg.db
|
||||
*/
|
||||
function getDatabasePath(): string {
|
||||
$env = getenv('DB_ENV');
|
||||
if ($env === 'test') {
|
||||
return DB_TEST_PATH;
|
||||
}
|
||||
if ($env === 'prod') {
|
||||
return DB_PROD_PATH;
|
||||
}
|
||||
|
||||
// Auto-detect: php built-in CLI server == local development
|
||||
if (php_sapi_name() === 'cli-server') {
|
||||
return DB_TEST_PATH;
|
||||
}
|
||||
|
||||
return DB_PROD_PATH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if running in local dev mode
|
||||
*/
|
||||
function isTestMode(): bool {
|
||||
return getDatabasePath() === DB_TEST_PATH;
|
||||
}
|
||||
Reference in New Issue
Block a user