Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.5.5
-
Fix Version/s: 4.6
-
Component/s: Core CiviCRM
-
Labels:None
-
Documentation Required?:None
Description
This seems to be a regression caused by CRM-15061.
CRM-15061 creates a new data structure, as saved in the civicrm_saved_search form_values field, for custom group/multi-select fields:
custom_NN = array('value1', 'value4', 'value5');
custon_NN_operator = 'or'
In 4.4, the data structure is:
custom_NN = array(
'value1' => 1,
'value2' =>
'value3' =>
'value4' => 1,
'value5' => 1
'CiviCRM_OP_OR' => 1
)
The 4.5 code properly saves new searches using the new data structure, but smart groups that have saved searches made during 4.4 still have the old structure which is incompatible with the new structure.
One option is to change the code to auto-detect which data structure is coming in. But that seems like it will simply preserve cruft we could do with out.
Here's some code that updates the saved search table converting to the new structure. I think this should be carefully reviewed since it could result in data loss:
$sql = "SELECT id, form_values FROM civicrm_saved_search";
$dao = CRM_Core_DAO::executeQuery($sql);
while($dao->fetch()) {
echo "Considering " . $dao->id . "\n";
$new = $data = unserialize($dao->form_values);
$update = FALSE;
while(list($field, $data_value) = each($data)) {
if(preg_match('/^custom_/', $field) && is_array($data_value)) {
if(array_key_exists('CiviCRM_OP_OR', $data_value)) {
// This indicates old-style data format. We need to fix it.
$update = TRUE;
$new_value = array();
$op = 'and';
if($data_value['CiviCRM_OP_OR'] == 1)
while(list($k, $v) = each($data_value)) {
if($v == 1)
}
// Overwrite old value.
$new[$field] = $new_value;
// Add new key for the operator.
$new["$
_operator"] = $op;
}
}
}
if($update)
}