User notifications: the administrator's guide
The kernel stores notifications per user (tables expusernotif and expusernotif_delivery), shows them in the admin4
bell and on a list page, and can deliver the same event through further channels. This page is for administrators:
subscriptions, channels, the outward switch and its guards, transports, the cron part, the console command, retention
and the policy. Extension authors find the API in Notifications for your extension;
users find the bell and the list page in Notifications: the user's guide. This is a separate
feature from the older e-mail notifications of content you follow.
All settings are in usernotification.ini. Do not edit the shipped file: use settings/override/ or
settings/siteaccess/<name>/. After a change clear the INI cache and all caches:
rm -f var/cache/ini/*.php
php bin/php/ezcache.php --clear-allSubscriptions: which channel a type uses
Each notification type (an identifier like workflow.stage_entered, registered by the kernel or an extension in
[Types] List[]) goes to the channels listed in [Subscriptions], separated by semicolons:
[Subscriptions]
Channels[]
Channels[*]=system
Channels[acme.order_shipped]=system;emailChannels[<type>] wins; a type without a line uses Channels[*] (shipped as system). The subscriptions belong to the
siteaccess in which the event happens, so a site can differ per siteaccess. A channel name that is unknown or not
available is skipped and logged; the other channels still run.
| Channel | What it does | When |
|---|---|---|
system | stores the notification (bell, list page) | at once |
browser | shows a one-time notice (at most [Bell] NoticeLimit, shipped 3) | at once |
log | writes a log line | at once |
email | one mail per recipient through the kernel's mail transport and its preferences | at once; a transport failure leaves a pending row for the cron part |
chat, sms, push | outward channels, see below | never inline: queued, sent by the cron part |
The e-mail channel does not send to a disabled account, a user without a valid address, a reserved address, or a
recipient whose mail preferences block it; each of these is recorded as a skipped row with the reason disabled,
no_address, reserved_domain or preference. Reserved addresses are those ending in a [Channel_email] SkipDomains[] value (.suffix matches a domain ending in it, @host that host exactly); without the key the five
values .invalid, .test, .example, .localhost and @localhost apply.
Outward channels and the switch
chat, sms and push post once per event to destinations the site configures, never once per recipient and never
to a user's address. The text is the type's reduced outward text: type label, counts, ids and absolute admin links,
never names, logins, addresses, phone numbers or content text.
Three gates must all be open, in this order:
- The switch.
[Outward] Delivery=disabledis the shipped default. Onlyenabledturns outward delivery on. With the switch off a queued row is recorded as skipped with the reasonoutward_off. - The source. The code that emits the event must pass the option
outward => true. Missing or false means no, and the row is skipped withsource_refused. - The guard of the source. A source may register
[Outward] Guards[<source>]=<Class>::<staticMethod>, a callable that returnstruewhen an outward message may leave. A guard that is registered but not callable, throws, or returns anything other thantruerefuses:guard_refused. The scripts whose events are never sent outward are listed by expworkflow in its ownexpworkflow.ini,[Outward] BulkScripts[].
The switch and the guard are checked twice: when the message is queued and again when the cron part sends it. A row queued before you turned the switch off therefore does not leave the site.
Other skip reasons you can meet in the delivery rows: unavailable (no transport could be built), no_destination
(SMS without a number), no_text (the type produced no outward text).
Transports and secrets
An outward channel needs a transport, one DSN per name:
[Transports]
Chat[<name>]=
Sms[<name>]=
Push[<name>]=
[Channel_sms]
To=[Channel_sms] To is the number the SMS channel posts to (the team number). The lists ship empty on purpose.
Put DSNs and the team number only in the secrets override of the installation (an INI override that is not in version control), never in settings/ or an extension's versioned INI; a
guard test fails on a non-empty DSN or To in a versioned file. A channel is available when at least one DSN can be
built into a transport. The transports come from the Symfony Notifier package; a DSN whose bridge is not installed
makes the channel unavailable (for SMS also without To). Install the bridge a DSN needs with Composer.
The cron part
usernotification.php is listed in cronjob.ini [CronjobPart-frequent], so it runs with the frequent cron part. In each
run it:
- sends up to
[Delivery] BatchSize(100) pending rows, oldest first: e-mail rows are sent again, outward rows are posted; - gives up on a row after
[Delivery] MaxAttempts(5) attempts; the row becomesfailed; - handles only rows queued by its own siteaccess (the links and settings of the message come from it) and counts
the pending rows of other siteaccesses it left alone. Run the cron part for each siteaccess that queues outward
messages (
-s <siteaccess>); - prints one line, for example
User notifications (siteaccess "site_admin"): 3 sent, 0 pending again, 0 failed, 1 skipped; 0 pending rows of other siteaccesses left alone; - once a day runs the retention cleanup (below). The day is kept in a stamp file
<vardir>/usernotification/cleanup.stamp; a failed cleanup is tried again at the next run.
Without the database tables (an installation not upgraded yet) the part prints a notice and does nothing.
The command
./console exp:usernotification:subscriptions -s <siteaccess>
./console exp:usernotification:subscriptions -s <siteaccess> --jsonUse this command instead of reading INI files: INI precedence between override, siteaccess and extensions is easy to
get wrong. For the siteaccess given with -s it prints each notification type with its channels as that siteaccess
resolves them, the channels that were skipped and why (unknown, no transport, no destination, outward_off, or the
error of a transport), the same for the default (a type without a line), whether each channel is available, the outward
switch and the registered guards. It changes nothing and shows no DSN or secret. The last line is Siteaccess <name>; other siteaccesses were not looked at; run the command once per siteaccess. --json prints the same as one JSON object
(siteaccess, note, types, default, channels, outward).
Retention
The daily cleanup of the cron part deletes, by age:
[Retention]
ReadDays=90
AllDays=365
DeliveryDays=30ReadDays for read notifications, AllDays for any notification (also unread), DeliveryDays for finished delivery rows
(sent, skipped, failed). The shipped values are in the example. 0 keeps that kind for good. The delivery rows of
a deleted notification go with it.
The policy and the bell
Every view of the module usernotification (the list page, opening a notification, the actions on the list page) needs
the policy usernotification/use. A role without it sees no bell, no list page and fetches nothing. Give the policy
to the roles whose users should receive notifications in the admin; it is not part of the shipped roles.
The bell is a header item of the admin4 design. It needs two things:
usernotification/use, andezjscore/call, because the bell loads its list from the feedezjscore/call/usernotification::notices. The policyezjscore/callmust be unlimited or limited to the function listusernotification(registered inezjscore.ini [ezjscServer] FunctionList[]). A user with a limitedezjscore/callthat lacksusernotificationsees an empty bell.
The bell is registered in the kernel's design.ini [AdminHeaderSettings] HeaderItems[] as
usernotification/header_bell.tpl. A siteaccess that resets HeaderItems[] in its own design.ini.append.php loses
the bell (and the items of every extension); if it needs its own list, keep the usernotification/header_bell.tpl line.
The header is cached per user and role, so after changing roles clear the caches as above.