Scheduled reminder: "Additional recipients" receive reminders under circumstances where they ought not to
This is a superset of event#28 (moved). The issue seems to be more generalized than I'd realized.
"Additional recipients" will receive reminders on events (and presumably other entities) that have been deleted. To test:
- Create a scheduled reminder for an existing event.
- Under Limit or Add Recipients, select Also Include and add a group or contact(s).
- Delete the event.
- Run the scheduled reminders job.
Expected result No scheduled reminder.
Actual result Scheduled reminder to the "additional recipients".
Why it happens
Scheduled reminder recipients are decided in two passes. First, whomever qualifies by the "normal" criteria (e.g. event participants) and a second pass for anyone in "Additional Participants".
The first pass is specific to the type of reminder (event, membership, contribution); the second is the same code regardless. This caused event#28 (moved); the "additional recipients" pass, by virtue of not being event/membership/etc-specific, wasn't aware that events have the special case of templates, which other entities don't. It also doesn't check for deleted entities.
The solution is to add a new method to the Civi\ActionSchedule\MappingInterface
interface - a sendToAdditional
method that returns a boolean. Then, each class that implements this interface can abort the "additional recipients" pass in an entity-specific way. Besides deleted entities and event templates, contributions have templates as well now, so we should check for that.