Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/includes/define.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion install/cli-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 9 additions & 3 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 <a href="<?= htmlspecialchars($_SERVER['REQUEST_URI'],
ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ?>" onclick="location.reload(true)">reload the page</a>
Expand Down Expand Up @@ -77,6 +76,13 @@
$content = "<?php\n\$install_session = '" . addslashes($sid) . "';\n\$install_ip = '" . addslashes($ip) . "';\n\$install_timestamp = " . $current_time . ";\n";
file_put_contents($lockfile, $content);
// Proceed
} elseif ($isLoopbackRequest && in_array($install_ip, ['127.0.0.1', '::1'], true)) {
// Local development can easily desync installer cookies between refreshes.
// On loopback, let the current browser session take over the installer lock
// instead of failing with an opaque 404.
$content = "<?php\n\$install_session = '" . addslashes($sid) . "';\n\$install_ip = '" . addslashes($ip) . "';\n\$install_timestamp = " . $current_time . ";\n";
file_put_contents($lockfile, $content);
// Proceed
} else {
// Block access
header('HTTP/1.1 404 Not Found');
Expand Down
8 changes: 7 additions & 1 deletion install/src/controllers/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@

include(EVO_BASE_PATH . '/index.php');

$installMigrationsPath = EVO_BASE_PATH . 'install/stubs/migrations';

if ($installMode != 0) {
bootstrapInstallMigrationHistory($installMigrationsPath);
}

if ($installMode != 0 && $database_type == 'pgsql') {
try {
$result = \DB::table('migrations_install')->select('id')->orderBy('id', 'DESC')->first();
Expand All @@ -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');
Expand Down
57 changes: 57 additions & 0 deletions install/src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ''];
Expand Down
2 changes: 1 addition & 1 deletion install/src/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down