Problem/Motivation
With issue #3521201, purging is gated on the user having a record in purge_users_notifications (written when the pre-deletion notification email is successfully sent).
Edge case raised in comment #15 there: if a user's email cannot be sent to, sendNotificationEmail() returns FALSE, no record is written, and the user is permanently stuck — matching purge criteria but never purgeable.
Two sub-cases admins may want to treat differently:
- Empty / NULL email — nothing for the admin to fix.
- Malformed email (e.g.
foo@@bar..com) — potentially a typo the admin could correct before the account is deleted.
Steps to reproduce
- Create a user with an empty or malformed email address.
- Configure a policy with the "Users pre-notified only" condition and pre-deletion notification enabled, short delay.
- Run the
notification_usersqueue and then cron. - Observe: the user stays in the queue forever, never moves to the purge phase.
Proposed resolution
Two new checkboxes, both default OFF to preserve current behavior on upgrade, added identically to the global Settings form and the Policy edit form, gated by #states on the pre-deletion notification being enabled:
treat_empty_email_as_notified— when checked, empty/NULL emails are auto-flagged as notified (writepurge_users_notificationsrow, skip the uselessmail()call, warning log).treat_invalid_email_as_notified— when checked, malformed emails (detected with Drupal email validator service) are also auto-flagged. UI-disabled until option 1 is checked.
Runtime resolution follows the existing cascade used by send_email_user_before_notification: when the policy's notification radio is enabled, the policy's own booleans drive; when default, the global booleans apply; when disabled, notifications are off so the question is moot.
Remaining tasks
- Extend
UserManagementService::notifyUser()andnotifyUserToPurge()with the auto-flag path. - Add the two checkboxes to
SettingsFormandPurgeUsersPolicyEditForm. - Add the two keys to the policy entity (properties, getters,
config_export). - Update config schema and install config defaults.
- Add
hook_update_Nto set defaults on existing installs. - Kernel tests covering empty/malformed/valid across default and opt-in config combinations, and policy-vs-global cascade.
User interface changes
Two new checkboxes in the "Notification User Before Deletion" section of both the Settings form and the Policy edit form.
API changes
None.
Data model changes
Two new config keys in purge_users.settings and on the purge_users_policy config entity. No schema changes to the database.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | Capture d’écran 2026-04-17 à 20.52.14.png | 127.85 KB | mably |
Issue fork purge_users-3585503
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mably commentedNew configuration options:
Comment #5
mably commentedComment #6
mably commented