Empty smart groups in CiviReport
We recently came across an odd problem with CiviReport. Every once in a while (hint, hint) CiviReport would display 0 results even though the smart group it was referencing did in fact have contacts. After spending some time going through the code with Xdebug and our favorite debugger we were not able to track down why the civicrm_group_contact_cache table would "randomly" empty itself.
Lobo and Deepak from the CiviCRM core team gave it their best, with Deepak even logging into our sandbox to help troubleshoot. The end result was, "well, it should just work if you update the smart group." Our savvy client already knew that updating the smart group fixes it but also knew that eventually the civicrm_group_contact_cache would be empty again.
We thought it might have something to do with cron and possibly some other module emptying the table, not CiviCRM. This particular site is running the Elysia Cron module so we rebuilt the cache table and starting manually running each of the jobs watching for the cache table to empty. The culprit turned out to be the CD Sunlight module. The client had 6.x-2.0 installed which is not compatible with CiviCRM 3.2.x/3.3.x. Using our debugger again, we isolated the problem to line 1618,
$contact = civicrm_contact_add($contact);
which tries to update a contact with their congressional district information and in the process clearing the civicrm_group_contact_cache table.
Updating to 6.x-3.0 solved the problem and provides compatibility with CiviCRM 3.3.x.
We also took the extra step to figure out why exactly CiviReport wasn't checking and populating the cache table. We filed a report on the CiviCRM issue tracker with a proposed patch.
Update: We've identified another bug related to caching behavior. You can read the details, but the moral of the story is: when comparing time/date stamps, make sure they come from the same source. Don't mix a database now() and PHP date() call. If you do, make sure you set a default timezone otherwise Drupal will use it's own timezone.
We often write "throw-away" code for one-off tasks or to scratch our own itch. The source might not be immediately useful for others but the lessons learned are invaluable. We always try to blog, tweet, or share those lessons when appropriate.
- Avalanche Forecast
- Breakout in Processing
- Brewfest Mobile App
- CiviCRM Discount
- CiviCRM Profile Permissions
- Danger Rose Field
- DB Tools
- Image Node Reference
- Linode Drupal StackScript
- Liquid Planner Shell
- OpenVZ Drupal Installer
- Randstring Safari Extension
- RSRA Database
- Ubercart/CiviCRM Integration
- User Login Block
- Webform Download Archive
In the process of writing custom software for our clients, we've also contributed bug fixes, patches, unit tests and documentation to various open source projects.



Comments
Post new comment