Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Major
-
Resolution: Fixed/Completed
-
Affects Version/s: 3.2, 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.3.0, 3.3.1, 3.3.2
-
Fix Version/s: 3.3.2
-
Component/s: CiviReport, Core CiviCRM
-
Labels:None
Description
This problem recently came up because a 3rd party module was calling civicrm_contact_add() on cron and clearing the civicrm_group_contact_cache table. Subsequent runs of CiviReport returned 0 contacts even though contacts do exist. Updating the smart group fixes the problem, until cron runs again.
The immediate fix was to update the 3rd party module to the latest version.
The more important fix is to make sure CiviReport is checking to see if the group exists in the cache table and if it doesn't, populate it.
Not completely understanding the caching mechanism in place, the best place to fix this seems to be in
CRM/Contact/BAO/GroupContactCache.php, check(), line 82 by adding the following:
// Populate the cache if empty or if the group id doesn't exist in the cache table
$query = "SELECT DISTINCT group_id FROM civicrm_group_contact_cache WHERE group_id IN ({$groupID})";
$dao =& CRM_Core_DAO::executeQuery($query);
$groupIDs = explode(',', $groupID);
$dbGroupIDs = array();
while ($dao->fetch())
$gids = array_diff($groupIDs, $dbGroupIDs);
foreach ($gids as $key => $gid)
return true;
It will check the groupids being used against the database and add any that are missing.