Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.6.5
-
Fix Version/s: 4.6.6
-
Component/s: None
-
Labels:None
-
Documentation Required?:None
-
Funding Source:Needs Funding
Description
I have a unit test that demonstrates this (using the api - which uses the same code) but basically the scenario is to have a contact who is a members of child group and of the parent group (which is not an uncommon config - especially for office users to be in both). The outcome can look like this (note this contact had been hard-added to 3 groups - Administrators, it's child summer volunteers and a smart group (Adams) that does not show up at all.
The query (with some changes to the SELECT part is below and the problematic part is the addition of OR in the join to civicrm_group added in CRM-16483 - this introduces lots of extra rows into the query - but most are filtered out by this line
https://github.com/fuzionnz/civicrm-core/blob/4.6/CRM/Contact/BAO/GroupContact.php#L409-409
I'm not quite sure the best fix but have managed to get a unit test to prove it / allow someone to replicate & fix via test. My instinct is that the problem is the OR introduced in CRM-16483 was in order to get the group name for smart groups and that should probably be resolved somewhere else - with the query in the Query object getting the right contacts & the group id being resolved to a group name closer to the calling function
SELECT
civicrm_group_contact.id, civicrm_group_contact.group_id, civicrm_group_contact.contact_id,
civicrm_group.id, civicrm_group.title,
civicrm_subscription_history.date, civicrm_group_contact_cache.*
FROM civicrm_contact contact_a
LEFT JOIN civicrm_group_contact ON contact_a.id = civicrm_group_contact.contact_id
LEFT JOIN civicrm_group_contact_cache ON civicrm_group_contact_cache.contact_id = contact_a.id
LEFT JOIN civicrm_group ON (
civicrm_group.id = civicrm_group_contact.group_id OR civicrm_group.id = civicrm_group_contact_cache.group_id)
LEFT JOIN civicrm_subscription_history
ON civicrm_group_contact.contact_id = civicrm_subscription_history.contact_id
AND civicrm_group_contact.group_id = civicrm_subscription_history.group_id
WHERE contact_a.id = 3 AND civicrm_group.is_active = 1 AND civicrm_group.saved_search_id
IS NULL AND civicrm_group.is_hidden = 0 AND civicrm_group_contact.status = 'Added' AND ( 1 )
ORDER BY civicrm_group.title, civicrm_subscription_history.date;