return TRUE;
}
+ /**
+ * Upgrade function.
+ *
+ * @param string $rev
+ */
+ public function upgrade_4_5_6($rev) {
+ // Task to process sql.
+ $this->addTask(ts('Upgrade DB to 4.5.6: Fix saved searches consisting of multi-choice custom field(s)'), 'updateSavedSearch');
+
+ return TRUE;
+ }
+
+ /**
+ * Update saved search for multi-select custom fields on DB upgrade
+ *
+ * @param CRM_Queue_TaskContext $ctx
+ *
+ * @return bool TRUE for success
+ */
+ static function updateSavedSearch(CRM_Queue_TaskContext $ctx) {
+ $sql = "SELECT id, form_values FROM civicrm_saved_search";
+ $dao = CRM_Core_DAO::executeQuery($sql);
+ while ($dao->fetch()) {
+ $formValues = unserialize($dao->form_values);
+ while (list($field, $data_value) = each($formValues)) {
+ if (preg_match('/^custom_/', $field) && is_array($data_value)) {
+ // This indicates old-style data format. We need to fix it.
+ $op = 'and';
+ if ($key = array_search('CiviCRM_OP_OR', $data_value)) {
+ $op = 'or';
+ unset($formValues[$field][$key]);
+ }
+
+ // Add new key for the operator.
+ $formValues["${field}_operator"] = $op;
+
+ $sql = "UPDATE civicrm_saved_search SET form_values = %0 WHERE id = %1";
+ CRM_Core_DAO::executeQuery($sql,
+ array(
+ array(serialize($formValues), 'String'),
+ array($dao->id, 'Integer'),
+ )
+ );
+ }
+ }
+ }
+
+ return TRUE;
+ }
+
+
/**
* (Queue Task Callback)
*/