diff --git a/core/includes/define.inc.php b/core/includes/define.inc.php index 3d1cf111d9..c47b1c3173 100644 --- a/core/includes/define.inc.php +++ b/core/includes/define.inc.php @@ -111,7 +111,9 @@ throw new RuntimeException('Please, use trailing slash at the end of EVO_BASE_URL'); } -define('EVO_MANAGER_PATH', EVO_BASE_PATH . MGR_DIR . '/'); +if (!defined('EVO_MANAGER_PATH')) { + define('EVO_MANAGER_PATH', EVO_BASE_PATH . MGR_DIR . '/'); +} if (!defined('EVO_SITE_URL')) { // check for valid hostnames diff --git a/install/cli-install.php b/install/cli-install.php index 5870b75a96..336c755f4b 100644 --- a/install/cli-install.php +++ b/install/cli-install.php @@ -165,7 +165,9 @@ public function initEvo() public function update() { $this->initEvo(); - Console::call('migrate', ['--path' => '../install/stubs/migrations', '--force' => true]); + $installMigrationsPath = EVO_BASE_PATH . 'install/stubs/migrations'; + bootstrapInstallMigrationHistory($installMigrationsPath); + Console::call('migrate', ['--path' => $installMigrationsPath, '--realpath' => true, '--force' => true]); seed('update'); echo 'Evolution CMS updated!' . "\n"; $this->checkRemoveInstall(); diff --git a/install/index.php b/install/index.php index 1277106c5f..c2fc71deb4 100644 --- a/install/index.php +++ b/install/index.php @@ -18,9 +18,6 @@ if (!defined('EVO_MANAGER_PATH')) { define('EVO_MANAGER_PATH', $base_path . MGR_DIR . '/'); } -if (!defined('EVO_MANAGER_PATH')) { - define('EVO_MANAGER_PATH', EVO_MANAGER_PATH); -} if (! defined('EVO_CORE_PATH')) { if (is_dir($base_path . 'core')) { define('EVO_CORE_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR); @@ -48,6 +45,8 @@ // Define lock file path $lockfile = $base_path . 'install.session.php'; +$isLoopbackRequest = in_array($ip, ['127.0.0.1', '::1'], true); + if (file_exists("{$base_path}manager/includes/config.inc.php")) { ?> Backup and delete the file `manager/includes/config.inc.php` then reload the page @@ -77,6 +76,13 @@ $content = "select('id')->orderBy('id', 'DESC')->first(); @@ -211,7 +217,7 @@ } } - Console::call('migrate', ['--path' => EVO_BASE_PATH . 'install/stubs/migrations', '--realpath' => true, '--force' => true]); + Console::call('migrate', ['--path' => $installMigrationsPath, '--realpath' => true, '--force' => true]); if ($installMode == 0) { seed('install'); diff --git a/install/src/functions.php b/install/src/functions.php index 4315a48763..4b132f3bf8 100644 --- a/install/src/functions.php +++ b/install/src/functions.php @@ -379,6 +379,63 @@ function getLangs($install_language) return implode("\n", $_); } +/** + * Existing installs may carry a single synthetic baseline row instead of the + * full historical install migration list. Register those older migrations so + * upgrade mode only runs genuinely new schema changes. + */ +function bootstrapInstallMigrationHistory(string $migrationsPath, string $baselineMigration = '2025_12_25_000000_initial_schema'): int +{ + if (!class_exists(\Illuminate\Support\Facades\DB::class) || + !class_exists(\Illuminate\Support\Facades\Schema::class) + ) { + return 0; + } + + try { + if (!\Illuminate\Support\Facades\Schema::hasTable('migrations_install') || + !\Illuminate\Support\Facades\Schema::hasTable('active_user_locks') + ) { + return 0; + } + + $registered = \Illuminate\Support\Facades\DB::table('migrations_install') + ->pluck('migration') + ->all(); + + if (!in_array($baselineMigration, $registered, true)) { + return 0; + } + + $historical = []; + foreach (glob(rtrim($migrationsPath, '/') . '/*.php') as $migrationFile) { + $migration = basename($migrationFile, '.php'); + if (strcmp($migration, $baselineMigration) < 0 && !in_array($migration, $registered, true)) { + $historical[] = $migration; + } + } + + if ($historical === []) { + return 0; + } + + sort($historical); + $batch = (int) (\Illuminate\Support\Facades\DB::table('migrations_install')->max('batch') ?: 1); + $rows = array_map(static function ($migration) use ($batch) { + return [ + 'migration' => $migration, + 'batch' => $batch, + ]; + }, $historical); + + \Illuminate\Support\Facades\DB::table('migrations_install')->insert($rows); + + return count($historical); + } catch (\Throwable $exception) { + return 0; + } +} + function sortItem($array = [], $order = 'utf8mb4,utf8') { $rs = ['recommend' => '']; diff --git a/install/src/lang.php b/install/src/lang.php index 1b0107d8eb..b919079082 100644 --- a/install/src/lang.php +++ b/install/src/lang.php @@ -15,7 +15,7 @@ #default fallback language file - english $install_language = 'en'; -$_langISO6391 = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); +$_langISO6391 = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', 0, 2); if (ctype_alpha($_langISO6391) && file_exists(__DIR__ . '/lang/' . $_langISO6391 . '.inc.php')) { $install_language = $_langISO6391; }