CRM-16081 - Fix unsubscribe error if groups are empty
authorColeman Watts <coleman@civicrm.org>
Wed, 1 Apr 2015 23:15:28 +0000 (19:15 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 1 Apr 2015 23:15:28 +0000 (19:15 -0400)
CRM/Mailing/Event/BAO/Unsubscribe.php

index 87232388def103dbfb4e2cc76792836fc5949d5e..10287840cf4d561bf507c4f674f43fd39d041e06 100755 (executable)
@@ -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')