CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • rebuild smart group cache / force a job to run immediately with an api call
Pages: [1]

Author Topic: rebuild smart group cache / force a job to run immediately with an api call  (Read 925 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
rebuild smart group cache / force a job to run immediately with an api call
September 03, 2013, 10:46:18 am
Hi

I have an ajax form in drupal on the users page (user/%uid), where there is a button which on click, change a custom field for the civicrm-contact matched to that user. The custom field can be yes or no. I also have a civicrm smart group where contacts having that costum field set to yes is in it.
My problem is: changing the custom field doesn't update the smart group cache, and therefore the change isn't reflected in the smartgroup before cron has run (the Rebuild Smart Group Cache job is set to run with cron). It needs to be updated immediately, because being in the group potentially means a lot of people calling that contact.
How do I rebuild the smart group cache immediately, whenever there is a change?



Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: rebuild smart group cache / force a job to run immediately with an api call
September 03, 2013, 01:39:24 pm

might need to invoke the function

CRM_Contact_BAO_GroupContactCache::remove

this queues the smart group for removal based on the smart group cache timeout parameter

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: rebuild smart group cache / force a job to run immediately with an api call
September 04, 2013, 01:36:30 pm
Thanks Lobo

I tried something like this:
require_once 'CRM/Contact/BAO/GroupContactCache.php';
CRM_Contact_BAO_GroupContactCache::remove( );

and it didn't work - maybe I'll also have to set the timeout  parameter to "now" ?

Anyway. I dropped using a smart group and instead just add/remove the contact from a 'normal' group in the ajax callback, and when the contact is created (via a profile) a do the same postProcess - then the change is reflected immediately. I guess it's less heavy on the system as well compared to removing and rebuilding the cache for smart groups.


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • rebuild smart group cache / force a job to run immediately with an api call

This forum was archived on 2017-11-26.