Fixes flash messages to show up only once per page

main
Yasen Pramatarov 2025-11-11 13:55:07 +02:00
parent 77f5921dff
commit 26c9f49138
2 changed files with 17 additions and 3 deletions

View File

@ -6,8 +6,18 @@
* Combines functionality to handle retrieving and displaying feedback messages.
*/
// Get any flash messages from previous request
$flash_messages = Feedback::getFlash();
// Prevent multiple display of flash messages on the same page
if (!isset($_SESSION['flash_messages_displayed'])) {
$_SESSION['flash_messages_displayed'] = false;
}
// Get any flash messages from previous request (only once per page load)
$flash_messages = [];
if (!$_SESSION['flash_messages_displayed']) {
$flash_messages = Feedback::getFlash();
$_SESSION['flash_messages_displayed'] = true;
}
if (!empty($flash_messages)) {
$system_messages = array_merge($system_messages ?? [], array_map(function($flash) {
return [

View File

@ -97,6 +97,9 @@ use app\Helpers\Theme;
Session::startSession();
// Reset flash messages display flag for new page load
$_SESSION['flash_messages_displayed'] = false;
// Define page variable early via sanitize
require_once __DIR__ . '/../app/includes/sanitize.php';
// Ensure $page is defined to avoid undefined variable
@ -185,9 +188,10 @@ if (isset($GLOBALS['user_IP'])) {
}
// Check for pending DB migrations (non-intrusive: warn only)
// Only show for authenticated users and not on login page
try {
$migrationsDir = __DIR__ . '/../doc/database/migrations';
if (is_dir($migrationsDir)) {
if (is_dir($migrationsDir) && $userId !== null && $page !== 'login') {
require_once __DIR__ . '/../app/core/MigrationRunner.php';
$runner = new \App\Core\MigrationRunner($db, $migrationsDir);
if ($runner->hasPendingMigrations()) {