From 3921b55db2b7a756af7492491410187d5c7ae854 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 1 Apr 2015 19:15:28 -0400 Subject: [PATCH] CRM-16081 - Fix unsubscribe error if groups are empty --- CRM/Mailing/Event/BAO/Unsubscribe.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CRM/Mailing/Event/BAO/Unsubscribe.php b/CRM/Mailing/Event/BAO/Unsubscribe.php index 87232388de..10287840cf 100755 --- a/CRM/Mailing/Event/BAO/Unsubscribe.php +++ b/CRM/Mailing/Event/BAO/Unsubscribe.php @@ -230,6 +230,10 @@ WHERE email = %2 if (!empty($base_group_ids)) { $baseGroupClause = "OR $group.id IN(" . implode(', ', $base_group_ids) . ")"; } + $groupIdClause = ''; + if ($group_ids || $base_group_ids) { + $groupIdClause = "AND $group.id IN (" . implode(', ', array_merge($group_ids, $base_group_ids)) . ")"; + } $do->query(" SELECT $group.id as group_id, $group.title as title, @@ -237,8 +241,8 @@ WHERE email = %2 FROM $group LEFT JOIN $gc ON $gc.group_id = $group.id - WHERE $group.id IN (" . implode(', ', array_merge($group_ids, $base_group_ids)) . ") - AND $group.is_hidden = 0 + WHERE $group.is_hidden = 0 + $groupIdClause AND ($group.saved_search_id is not null OR ($gc.contact_id = $contact_id AND $gc.status = 'Added') -- 2.25.1