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

  1. Create a user with an empty or malformed email address.
  2. Configure a policy with the "Users pre-notified only" condition and pre-deletion notification enabled, short delay.
  3. Run the notification_users queue and then cron.
  4. 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:

  1. treat_empty_email_as_notified — when checked, empty/NULL emails are auto-flagged as notified (write purge_users_notifications row, skip the useless mail() call, warning log).
  2. 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() and notifyUserToPurge() with the auto-flag path.
  • Add the two checkboxes to SettingsForm and PurgeUsersPolicyEditForm.
  • Add the two keys to the policy entity (properties, getters, config_export).
  • Update config schema and install config defaults.
  • Add hook_update_N to 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.

Command icon 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

mably created an issue. See original summary.

mably’s picture

New configuration options:

New configuration options

mably changed the visibility of the branch 3585503-configurable-handling-of to hidden.

mably’s picture

Status: Active » Needs review
mably’s picture

Issue summary: View changes