Problem/Motivation
In recurring_events_reminders_cron, if one of the event instances marked for sending reminders has no registrants, the loop breaks and the remaining instances in the list are left unprocessed. As a result, you must wait until the next cron run, hoping that no other empty instances are encountered, before the reminders for valid instances are eventually processed and notifications are sent.
This happens because the function uses return instead of continue at this point in the code:
recurring_events_reminders/recurring_events_reminders.module
foreach ($instances as $instance) {
$instance->set('reminder_sent', time());
$instance->setNewRevision(FALSE);
$instance->save();
/** @var \Drupal\recurring_events_registration\RegistrationCreationService */
$registration_creation_service = \Drupal::service('recurring_events_registration.creation_service');
$registration_creation_service->setEventInstance($instance);
$registrants = $registration_creation_service->retrieveRegisteredParties();
if (empty($registrants)) {
return; // This breaks the process if an instance has no registrants, leaving remaining instances unprocessed.
}
$key = 'registration_reminder';
// Send an email to all registrants.
foreach ($registrants as $registrant) {
// Add each notification to be sent to the queue.
\Drupal::service('recurring_events_registration.notification_service')->addEmailNotificationToQueue($key, $registrant);
}
}
Steps to reproduce
- Create a series with reminders enabled and multiple instances.
- Add a couple of registrants to the last instance in the series.
- Leave the other instances without registrants.
- Run cron, expecting the reminders to be sent to the registrants you created.
- Notice that execution breaks when it encounters the first instance without registrants.
- Observe that cron must be run several times before it eventually reaches the instance with registrants and sends the reminders.
Proposed resolution
If an instance does not have registrants, the process should continue with the next instance in the list.
Replace return with continue.
Remaining tasks
Create MR (done).
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork recurring_events-3545213
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 #3
camilo.escobar commentedComment #4
camilo.escobar commented