From 1c9cf44336e54ba7dcbaba6d9dc11532dd2ee4dc Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Mon, 3 Aug 2015 17:46:07 +0200 Subject: [PATCH] CRM-16036 - Fix for chaining. When using a custom field as param for the API, chaining didn't work as it should. This is a fix. I have a unit test for this as well, but it depends on a fix for CRM-16168, so if I add it here, it will break anyway. I will document this in the issue itself. ---------------------------------------- * CRM-16036: API: searching on custom fields does not work https://issues.civicrm.org/jira/browse/CRM-16036 * CRM-16168: Chained call event-loc block returns an error if no loc block exists. https://issues.civicrm.org/jira/browse/CRM-16168 --- api/v3/utils.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/api/v3/utils.php b/api/v3/utils.php index d29dedd8c9..70a1de26ff 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -474,13 +474,22 @@ function _civicrm_api3_store_values(&$fields, &$params, &$values) { * @return array */ function _civicrm_api3_get_using_query_object_simple($dao_name, $params, $return_as_success = TRUE) { + // In CiviCRM 4.6.5, if your call has a nested call, and in this + // nested call you use the id (e.g. "id" => "$value.some_id"), the parent + // call will get a param "id" => NULL. Not sure whether this is expected + // behaviour or a bug. But I'll have to work around it. + if (array_key_exists('id', $params) && $params['id'] === null) { + unset($params['id']); + } + $dao = new $dao_name(); $entity = _civicrm_api_get_entity_name_from_dao($dao); $custom_fields = _civicrm_api3_custom_fields_for_entity($entity); $options = _civicrm_api3_get_options_from_params($params); - + $entity_field_names = _civicrm_api3_field_names( _civicrm_api3_build_fields_array($dao)); + $custom_field_names = array(); // $select_fields maps column names to the field names of the result // values. @@ -509,6 +518,7 @@ function _civicrm_api3_get_using_query_object_simple($dao_name, $params, $return // custom fields foreach ($custom_fields as $cf_id => $custom_field) { $field_name = "custom_$cf_id"; + $custom_field_names[] = $field_name; if ($return_all_fields || !empty($options['return'][$field_name])) { $table_name = $custom_field["table_name"]; $column_name = $custom_field["column_name"]; @@ -538,6 +548,11 @@ function _civicrm_api3_get_using_query_object_simple($dao_name, $params, $return // populate $where_clauses foreach ($params as $key => $value) { + if (!in_array($key, $entity_field_names) && !in_array($key, $custom_field_names)) { + // No valid filter field. This might be a chained call or something. + // Just ignore this for the $where_clause. + continue; + } if (!is_array($value)) { $operator = "="; $rhs = $value; -- 2.25.1