Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplication of unsent scheduled reminders #31600

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Civi/ActionSchedule/RecipientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ protected function buildRelRepeatPass() {
// the first part of the startDateClause array is the earliest the reminder can be sent. If the
// event (e.g membership_end_date) has changed then the reminder may no longer apply
// @todo - this only handles events that get moved later. Potentially they might get moved earlier
// also, do not create any more entries if there are unprocessed ones still pending
$repeatInsert = $query
->merge($this->joinReminder('INNER JOIN', 'rel', $query))
->merge($this->selectIntoActionLog(self::PHASE_RELATION_REPEAT, $query))
->merge($this->prepareRepetitionEndFilter($query['casDateField']))
->where($this->actionSchedule->start_action_date ? $startDateClauses[0] : [])
->groupBy("reminder.contact_id, reminder.entity_id, reminder.entity_table")
->having("SUM(ISNULL(reminder.action_date_time)) = 0")
->having("TIMESTAMPDIFF(HOUR, MAX(reminder.action_date_time), CAST(!casNow AS datetime)) >= TIMESTAMPDIFF(HOUR, MAX(reminder.action_date_time), DATE_ADD(MAX(reminder.action_date_time), INTERVAL !casRepetitionInterval))")
->param([
'casRepetitionInterval' => $this->parseRepetitionInterval(),
Expand Down Expand Up @@ -256,6 +258,7 @@ protected function buildAddlRepeatPass() {
->merge($this->prepareAddlFilter('c.id'), ['params'])
->where("c.is_deleted = 0 AND c.is_deceased = 0")
->groupBy("reminder.contact_id")
->having("SUM(ISNULL(reminder.action_date_time)) = 0")
->having("TIMESTAMPDIFF(HOUR, MAX(reminder.action_date_time), CAST(!casNow AS datetime)) >= TIMESTAMPDIFF(HOUR, MAX(reminder.action_date_time), DATE_ADD(MAX(reminder.action_date_time), INTERVAL !casRepetitionInterval))")
->param([
'casRepetitionInterval' => $this->parseRepetitionInterval(),
Expand Down Expand Up @@ -317,6 +320,9 @@ protected function parseRepetitionInterval() {
elseif ($actionSchedule->repetition_frequency_unit == 'year') {
$interval = "{$actionSchedule->repetition_frequency_interval} YEAR";
}
elseif ($actionSchedule->repetition_frequency_unit == 'minute') {
$interval = "{$actionSchedule->repetition_frequency_interval} MINUTE";
}
else {
$interval = "{$actionSchedule->repetition_frequency_interval} HOUR";
}
Expand Down