Capture app version and defer notifications

Installer: capture the current app version (fromVersion) before running migrations, with a fallback for very old installs where settings may not exist. Re-read the app version after migrations to determine toVersion and only use migration-based detection as a fallback when the version didn't change.

Update flow: only send admin upgrade notifications when there are no pending migrations. If migrations remain, the user is redirected to the installer which will send the correct notification after migrations complete. This prevents duplicate or incorrect upgrade notifications and ensures accurate from/to version reporting.
This commit is contained in:
Hosteroid
2026-02-11 18:44:06 +02:00
parent 3688c8b71b
commit 4371f174c9
2 changed files with 43 additions and 30 deletions

View File

@@ -578,6 +578,16 @@ class InstallerController extends Controller
$migrations = $this->getPendingMigrations();
$executed = [];
// Capture current app version BEFORE running migrations (so we know the real "from" version)
$fromVersion = null;
try {
$settingModel = new \App\Models\Setting();
$fromVersion = $settingModel->getAppVersion();
} catch (\Exception $e) {
// Settings table may not exist yet for very old installs
$fromVersion = '1.0.0';
}
// Ensure migrations table exists for tracking
$pdo->exec("
CREATE TABLE IF NOT EXISTS migrations (
@@ -639,24 +649,23 @@ class InstallerController extends Controller
]);
try {
// Re-read the app version AFTER migrations to get the "to" version
$settingModel = new \App\Models\Setting();
$currentVersion = $settingModel->getAppVersion();
$toVersion = $settingModel->getAppVersion();
// Determine from/to versions based on migrations
$fromVersion = '1.0.0';
$toVersion = '1.1.3';
// Detect version based on which migrations were run
if (in_array('025_add_update_system_v1.1.3.sql', $executed)) {
$toVersion = '1.1.3';
} elseif (in_array('024_add_status_notifications_v1.1.2.sql', $executed)) {
$toVersion = '1.1.2';
} elseif (in_array('022_add_pushover_channel_type.sql', $executed)) {
$toVersion = '1.1.1';
} elseif (in_array('011_create_sessions_table.sql', $executed) ||
in_array('012_link_remember_tokens_to_sessions.sql', $executed) ||
in_array('013_create_user_notifications_table.sql', $executed)) {
$toVersion = '1.1.0';
// Fallback: detect "to" version from which migrations were run
if ($toVersion === $fromVersion) {
if (in_array('025_add_update_system_v1.1.3.sql', $executed)) {
$toVersion = '1.1.3';
} elseif (in_array('024_add_status_notifications_v1.1.2.sql', $executed)) {
$toVersion = '1.1.2';
} elseif (in_array('022_add_pushover_channel_type.sql', $executed)) {
$toVersion = '1.1.1';
} elseif (in_array('011_create_sessions_table.sql', $executed) ||
in_array('012_link_remember_tokens_to_sessions.sql', $executed) ||
in_array('013_create_user_notifications_table.sql', $executed)) {
$toVersion = '1.1.0';
}
}
$notificationService = new \App\Services\NotificationService();