From: Eileen McNaughton Date: Mon, 15 Sep 2014 04:24:46 +0000 (+1200) Subject: CRM-15299 generic fix on handling apistyle query filters in query object X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=461c9a60b19c647e14949c76f6157a0744f07f86;p=civicrm-core.git CRM-15299 generic fix on handling apistyle query filters in query object --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index f7391601a2..96bfeffccd 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -5201,7 +5201,14 @@ SELECT COUNT( conts.total_amount ) as cancel_count, if (empty($dataType)) { $dataType = 'String'; } - + if (is_array($value)) { + //this could have come from the api - as in the restWhere section we potentially use the api operator syntax which is becoming more + // widely used and consistent across the codebase + // adding this here won't accept the search functions which don't submit an array + if (($queryString = CRM_Core_DAO::createSqlFilter($field, $value, $dataType)) != FALSE) { + return $queryString; + } + } $value = CRM_Utils_Type::escape($value, $dataType); // if we don't have a dataType we should assume if ($dataType == 'String' || $dataType == 'Text') { diff --git a/api/v3/Domain.php b/api/v3/Domain.php index 365708f4de..2888fa9981 100644 --- a/api/v3/Domain.php +++ b/api/v3/Domain.php @@ -52,6 +52,9 @@ function civicrm_api3_domain_get($params) { $domainBAO = CRM_Core_Config::domainID(); $params['id'] = $domainBAO; } + if (!empty($params['options']) && !empty($params['options']['is_count'])) { + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + } _civicrm_api3_dao_set_filter($bao, $params, true, 'domain'); $domains = _civicrm_api3_dao_to_array($bao, $params, true,'domain'); diff --git a/api/v3/utils.php b/api/v3/utils.php index c4eb611213..8c08e91a21 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -548,14 +548,12 @@ function _civicrm_api3_get_query_object($params, $mode, $entity) { */ function _civicrm_api3_dao_set_filter(&$dao, $params, $unique = TRUE, $entity) { $entity = substr($dao->__table, 8); - - $allfields = _civicrm_api3_build_fields_array($dao, $unique); - - $fields = array_intersect(array_keys($allfields), array_keys($params)); - if (isset($params[$entity . "_id"])) { + if (!empty($params[$entity . "_id"]) && empty($params['id'])) { //if entity_id is set then treat it as ID (will be overridden by id if set) - $dao->id = $params[$entity . "_id"]; + $params['id'] = $params[$entity . "_id"]; } + $allfields = _civicrm_api3_build_fields_array($dao, $unique); + $fields = array_intersect(array_keys($allfields), array_keys($params)); $options = _civicrm_api3_get_options_from_params($params); //apply options like sort