Fix database schema drop order, enhance migrate.php, and support server env paths

This commit is contained in:
Hamza-Ayed
2026-08-26 17:39:08 +03:00
parent e944d92aac
commit 702730702d
3 changed files with 66 additions and 26 deletions
+18 -7
View File
@@ -30,15 +30,26 @@ spl_autoload_register(function ($class) {
// 2. Load Environment Variables
try {
// Find the closest .env file path (supporting local development and CloudPanel server directories)
$env_file = APP_ROOT . '/.env';
if (!file_exists($env_file)) {
if (file_exists(APP_ROOT . '/../../../.env')) {
$env_file = APP_ROOT . '/../../../.env';
} elseif (file_exists(APP_ROOT . '/../.env')) {
$env_file = APP_ROOT . '/../.env';
$candidatePaths = [
APP_ROOT . '/.env',
APP_ROOT . '/../.env',
APP_ROOT . '/../../.env',
APP_ROOT . '/../../../.env',
APP_ROOT . '/../../../../.env',
'/home/intaleqapp-saqel/.env'
];
$env_file = null;
foreach ($candidatePaths as $path) {
if (file_exists($path)) {
$env_file = $path;
break;
}
}
\App\Core\Env::load($env_file);
if ($env_file) {
\App\Core\Env::load($env_file);
} else {
throw new \RuntimeException("No .env file found in candidate paths");
}
} catch (\Exception $e) {
// In production, log error; in development, print it
error_log('Env Load Error: ' . $e->getMessage());