From: Johan Vervloet Date: Tue, 10 Mar 2015 15:07:45 +0000 (+0100) Subject: CRM-16036 - A hack around the issue. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6a271fe04d062e9a55daa50582ea7a9b8327f54a;p=civicrm-core.git CRM-16036 - A hack around the issue. I changed _civicrm_api3_basic_get so that it calls my hack (_civicrm_api3_get_using_query_object_simple) whenever a custom field is used in $params. In all other cases, the API behaves as before. ---------------------------------------- * CRM-16036: API: searching on custom fields does not work https://issues.civicrm.org/jira/browse/CRM-16036 --- diff --git a/api/v3/utils.php b/api/v3/utils.php index 57ccc4ae48..b3dfe2a084 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -467,10 +467,13 @@ function _civicrm_api3_store_values(&$fields, &$params, &$values) { * @param string $dao_name * Name of DAO * @param array $params - * As passed into api get function. + * As passed into api get function. + * @param bool $return_as_success + * Return in api success format. + * * @return array */ -function _civicrm_api3_get_using_query_object_simple($dao_name, $params) { +function _civicrm_api3_get_using_query_object_simple($dao_name, $params, $return_as_success = TRUE) { $dao = new $dao_name(); $entity = _civicrm_api_get_entity_name_from_dao($dao); $custom_fields = _civicrm_api3_custom_fields_for_entity($entity); @@ -625,7 +628,12 @@ function _civicrm_api3_get_using_query_object_simple($dao_name, $params) { } $result_dao->free(); - return civicrm_api3_create_success($result_entities, $params, $entity, 'get', $dao); + if ($return_as_success) { + return civicrm_api3_create_success($result_entities, $params, $entity, 'get', $dao); + } + else { + return $result_entities; + } } /** @@ -1488,6 +1496,15 @@ function _civicrm_api3_check_required_fields($params, $daoName, $return = FALSE) * @return array */ function _civicrm_api3_basic_get($bao_name, &$params, $returnAsSuccess = TRUE, $entity = "") { + // if $params refers to a custom field, use a hack to + // avoid CRM-16036 + foreach (array_keys($params) as $key) { + if (substr($key, 0, 7) == 'custom_') { + return _civicrm_api3_get_using_query_object_simple( + $bao_name, $params, $returnAsSuccess); + } + } + $bao = new $bao_name(); _civicrm_api3_dao_set_filter($bao, $params, TRUE); if ($returnAsSuccess) {