From 8df0c9e052c26da551c026ded26319001784b4fd Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 21 Aug 2020 17:20:58 +1200 Subject: [PATCH] Metadata fix in activity search This fixes it such that even if the pseudofield (activity_type) has a 'type' the 'type' from the 'real field' is used in the WHERE query. This mostly prevents a test fail per https://github.com/civicrm/civicrm-core/pull/18147 if we improve the metadata. It's a bit of a non-fail fail - ie we are checking the where clause has activity_type_id = 3 vs '3' and my testing has not shown a performance difference but we don't want the test to be changed to the less good version --- CRM/Activity/BAO/Query.php | 2 +- CRM/Contact/BAO/Query.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 20dd823853..d432467e8d 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -189,7 +189,7 @@ class CRM_Activity_BAO_Query { // We no longer expect "subject" as a specific criteria (as of CRM-19447), // but we still use activity_subject in Activity.Get API case 'activity_subject': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldSpec['where'], $op, $value, CRM_Utils_Type::typeToString($fieldSpec['type'])); + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldSpec['where'], $op, $value, $query->getDataTypeForRealField($name)); $query->_qill[$grouping][] = $query->getQillForField($fieldSpec['is_pseudofield_for'] ?? $fieldSpec['name'], $value, $op, $fieldSpec); break; diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 6f8c8fc893..3fe9a97fc2 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -6941,6 +6941,17 @@ AND displayRelType.is_active = 1 return $field; } + /** + * Get the field datatype, using the type in the database rather than the pseudofield, if a pseudofield. + * + * @param string $fieldName + * + * @return string + */ + public function getDataTypeForRealField($fieldName) { + return CRM_Utils_Type::typeToString($this->getMetadataForRealField($fieldName)['type']); + } + /** * If we have a field that is better rendered via the pseudoconstant handled them here. * -- 2.25.1