#111694Deliver flash messages to a backend user from CLI and async tasks
Description
Motivation
Flash messages and backend notifications are designed for the backend user of the current request. FlashMessageQueue stores session messages in the session data of the current user (core.template.flashMessages, core.template.notifications), which it takes from $GLOBALS['BE_USER'] (or the frontend user).
This works well for feedback within a request. Code that reports to a user from outside that user’s request has no way to use them:
- console commands and scheduler tasks (the CLI user
_cli_has no backend session), - message handlers of the Symfony Messenger bus (#97700), running in a worker (
messenger:consume), - other asynchronous work started by a user, e.g. an import, a file conversion or a long-running DataHandler operation handed over to a queue.
When such work is done or has failed, the user who started it gets no feedback in the backend. Extensions fall back to e-mails, sys_log entries barely read, or their own tables and modules.
Proposal
Allow code to address a flash message or notification to a specific backend user. The message is stored persistently and delivered the next time that user loads the backend, in the same way as a session message today.
- A service, e.g.
BackendUserMessageService::addMessage(int $backendUserUid, FlashMessage $message, string $queueIdentifier = FlashMessageQueue::NOTIFICATION_QUEUE), usable without a backend user in context (CLI, worker). - A persistent storage independent of the session, e.g. a table with backend user uid, queue identifier, serialized message (
FlashMessageis JSON serializable since #93063) and creation time. - On the next backend request of that user, pending messages are moved into the requested queue of the current session and removed from the storage. Notifications then show up through the existing rendering (
ModuleTemplate,BackendController).
Points to decide
- Language: the sender does not run in the language of the receiver. Messages should allow translation keys with arguments that are resolved when they are delivered, in the language of the receiving user.
- Several sessions: a message is delivered once, to the first session of the user that picks it up.
- Cleanup: messages for deleted or disabled users and messages that are never picked up need an expiry, e.g. through the table garbage collection task.
- Recipients: a single backend user is the base case. Backend user groups or “all admins” could follow.
- Delivery while the backend is open: without polling, a message only shows up on the next page load or module change. Live delivery could be a later step.
Use case
An editor starts an import in a backend module. The module dispatches a message to the Messenger bus and returns immediately. The handler runs in a worker and, when done, adds a notification “Import finished: 120 records created, 3 failed” for that editor. The editor sees it with the next click in the backend.
Reviews 1
History 12
-
Markus Hofmann changed description 12/01/26, 10:33
-
Gerrit Code Review pushed patch set 1 for main to change 98259 status
NewUnder Review 12/01/26, 11:06