Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Major
-
Resolution: Duplicate
-
Affects Version/s: 4.7.3
-
Fix Version/s: None
-
Component/s: CiviCRM API, Core CiviCRM
-
Labels:None
-
Documentation Required?:Developer Doc
-
Funding Source:Core Team Funds
Description
Hi,
I've seen some issues where a member gets multiple (identical) membership reminders (at the same time, in the same send_reminders job) when someone has manually (generally through the API) changed a membership end date.
I think the issue is because when you change membership end dates manually, the corresponding date in the civicrm_action_log table doesn't get updated.
Somewhere in this monster query:
{{SELECT e.end_date, e.contact_id as contact_id, e.id as entity_id, "civicrm_membership" as entity_table, 2 as action_schedule_id
FROM civicrm_membership e
INNER JOIN civicrm_contact c ON c.id = e.contact_id AND c.is_deleted = 0 AND c.is_deceased = 0
LEFT JOIN civicrm_action_log reminder ON reminder.contact_id = e.contact_id AND
reminder.entity_id = e.id AND
reminder.entity_table = 'civicrm_membership' AND
reminder.action_schedule_id = 2
WHERE (e.membership_type_id IN ("1", "2", "3", "8", "11", "6")) AND (( e.is_override IS NULL OR e.is_override = 0 )) AND (e.status_id IN (1, 2, 3, 4)) AND (reminder.id IS NOT NULL) AND ('20160310203547' >= DATE_SUB(e.end_date, INTERVAL 3 week)) AND (DATE_SUB(20160310203547, INTERVAL 1 DAY ) <= DATE_SUB(e.end_date, INTERVAL 3 week)) AND (reminder.action_date_time IS NOT NULL AND reminder.reference_date IS NOT NULL)
GROUP BY reminder.id, reminder.reference_date
HAVING (reminder.id = MAX(reminder.id) AND reminder.reference_date <> e.end_date)}}
I get 4 identical results (same entity, same contact_id). This query gets generated here: Civi/ActionSchedule/RecipientBuilder.php (I am fairly sure of that).
I can solve it in this query simply by adding 'DISTINCT' after the SELECT but I'm unsure whether my reasoning is correct, whether that IS how CiviCRM decides to send reminders and then the other issue is - how/where do I add the distinct and to which query.
Thank you!