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:
@@ -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,14 +649,12 @@ 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
|
||||
// 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)) {
|
||||
@@ -658,6 +666,7 @@ class InstallerController extends Controller
|
||||
in_array('013_create_user_notifications_table.sql', $executed)) {
|
||||
$toVersion = '1.1.0';
|
||||
}
|
||||
}
|
||||
|
||||
$notificationService = new \App\Services\NotificationService();
|
||||
$notificationService->notifyAdminsUpgrade($fromVersion, $toVersion, count($executed));
|
||||
|
||||
@@ -109,7 +109,10 @@ class UpdateController extends Controller
|
||||
// Check for pending migrations after file update
|
||||
$hasMigrations = $this->updateService->hasPendingMigrations();
|
||||
|
||||
// Notify admins
|
||||
// Only notify admins if there are NO pending migrations.
|
||||
// When migrations are pending, the user is redirected to /install/update
|
||||
// which sends the upgrade notification after migrations complete (with the correct count).
|
||||
if (!$hasMigrations) {
|
||||
try {
|
||||
$notificationService = new NotificationService();
|
||||
$notificationService->notifyAdminsUpgrade(
|
||||
@@ -124,6 +127,7 @@ class UpdateController extends Controller
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$message = "Update applied successfully! {$filesUpdated} file(s) updated.";
|
||||
if (!empty($result['db_backup_warning'])) {
|
||||
|
||||
Reference in New Issue
Block a user