From cbfe52329b053a2dfea15995c7376890c093cd14 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Sat, 20 Jun 2015 03:43:30 +0530 Subject: [PATCH] improvement fixes --- CRM/Core/BAO/CustomQuery.php | 5 +++-- api/v3/utils.php | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index 990e277086..21894ef732 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -405,13 +405,14 @@ SELECT label, value $value = CRM_Utils_Type::escape($strtolower($value), 'String'); } // in api sometimes params is in array('sqlOp' => (mixed)'values') format - elseif (!empty($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + elseif (!empty($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE) || strstr(key($value), 'EMPTY')) { $op = key($value); + $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); $value = CRM_Utils_Type::escape($strtolower($value[$op]), 'String'); } if (strstr($op, 'NULL') || strstr($op, 'EMPTY')) { - $value = NULL; + $qillValue = $value = NULL; } elseif ($isSerialized && strstr($op, 'IN')) { $value = implode(',', $value); diff --git a/api/v3/utils.php b/api/v3/utils.php index 08536a9850..88b3b8c665 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -2059,7 +2059,7 @@ function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) { * @throws Exception */ function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $entity) { - list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName); + list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName, 'String'); if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE || CRM_Utils_System::isNull($fieldValue)) { return; } @@ -2259,18 +2259,22 @@ function _civicrm_api3_deprecation_check($entity, $result = array()) { * Get the actual field value. * * In some case $params[$fieldName] holds Array value in this format Array([operator] => [value]) - * So this function returns the actual field value + * So this function returns the actual field value. * * @param array $params * @param string $fieldName + * @param string $type * * @return mixed */ -function _civicrm_api3_field_value_check(&$params, $fieldName) { +function _civicrm_api3_field_value_check(&$params, $fieldName, $type = NULL) { $fieldValue = CRM_Utils_Array::value($fieldName, $params); $op = NULL; - if (!empty($fieldValue) && is_array($fieldValue) && array_search(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) { + if (!empty($fieldValue) && is_array($fieldValue) && + (array_search(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators()) || + $type == 'String' && strstr(key($fieldValue), 'EMPTY')) + ) { $op = key($fieldValue); $fieldValue = CRM_Utils_Array::value($op, $fieldValue); } -- 2.25.1