From 472e3d84a2916bea6968066ed057037b433642ea Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Wed, 25 Jan 2017 14:40:40 +0530 Subject: [PATCH] CRM-19924: Unsubscribe from a mailing sent to a parent group silently fails --- CRM/Mailing/Event/BAO/Unsubscribe.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/CRM/Mailing/Event/BAO/Unsubscribe.php b/CRM/Mailing/Event/BAO/Unsubscribe.php index 461ba9bd78..01ab5a1751 100644 --- a/CRM/Mailing/Event/BAO/Unsubscribe.php +++ b/CRM/Mailing/Event/BAO/Unsubscribe.php @@ -216,21 +216,23 @@ WHERE email = %2 } //Pass the groups to be unsubscribed from through a hook. - $group_ids = array_keys($groups); - $base_group_ids = array_keys($base_groups); - CRM_Utils_Hook::unsubscribeGroups('unsubscribe', $mailing_id, $contact_id, $group_ids, $base_group_ids); + $groupIds = array_keys($groups); + //include child groups if any + $groupIds = array_merge($groupIds, CRM_Contact_BAO_Group::getChildGroupIds($groupIds)); + + $baseGroupIds = array_keys($base_groups); + CRM_Utils_Hook::unsubscribeGroups('unsubscribe', $mailing_id, $contact_id, $groupIds, $baseGroupIds); // Now we have a complete list of recipient groups. Filter out all // those except smart groups, those that the contact belongs to and // base groups from search based mailings. - $baseGroupClause = ''; - if (!empty($base_group_ids)) { - $baseGroupClause = "OR $group.id IN(" . implode(', ', $base_group_ids) . ")"; + if (!empty($baseGroupIds)) { + $baseGroupClause = "OR $group.id IN(" . implode(', ', $baseGroupIds) . ")"; } $groupIdClause = ''; - if ($group_ids || $base_group_ids) { - $groupIdClause = "AND $group.id IN (" . implode(', ', array_merge($group_ids, $base_group_ids)) . ")"; + if ($groupIds || $baseGroupIds) { + $groupIdClause = "AND $group.id IN (" . implode(', ', array_merge($groupIds, $baseGroupIds)) . ")"; } $do->query(" SELECT $group.id as group_id, @@ -267,7 +269,7 @@ WHERE email = %2 foreach ($groups as $group_id => $group_name) { $notremoved = FALSE; if ($group_name) { - if (in_array($group_id, $base_group_ids)) { + if (in_array($group_id, $baseGroupIds)) { list($total, $removed, $notremoved) = CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Removed'); } else { -- 2.25.1