While upgrading from CiviCRM 4.6 to 5.10.x , old smartgroups stopped refreshing contacts
Steps to reproduce:
- Save a smartgroup that was using eg. a customfield value on a CiviCRM 4.6.x environment
- Migrate to the latest CiviCRM
- Change a contact so that the change can reflect to that smartgroup
- Do a simple search using this smartgroup. Contact should not appear.
drush cvapi job.group_rebuild
doesn't fix the issue.
Resolution: We traced this down to the fact that old form values and in general saved search settings were not being converted to new form values during the upgrade process.
There are 2 possible solutions on this:
- Open the smartgroup criteria, do a search and
update smartgroup
. This is efficient if there are not many smartgroups in the installation. - Include a fix during the upgrade process that will call in essence those lines:
// Read the existing form values
$formValues = CRM_Contact_BAO_SavedSearch::getFormValues($SavedSearchId);
// Update saved search record.
$savedSearch = new CRM_Contact_BAO_SavedSearch();
$savedSearch->id = $SavedSearchId;
$savedSearch->form_values = serialize(CRM_Contact_BAO_Query::convertFormValues($formValues));
$savedSearch->save();
In our case, we followed this path:
- We've made a custom API call to do a search for all smartgroups and then apply the above fix on each one of these.
- Then we issued a
TRUNCATE TABLE civicrm_group_contact_cache
. - Lastly, we issued a
drush cvapi job.group_rebuild
to force a smartgroup rebuild.
It seems that it's fixing our issue.
Do you believe that the upgrader needs a patch to resolve this situation?