Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#3495 - Fix fields with wildcards in Advanced Search #23697

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -6309,15 +6309,13 @@ public static function getQillValue($daoName, string $name, $value, $op, string
public static function getWildCardedValue($wildcard, $op, $value) {
if ($wildcard && $op === 'LIKE') {
if (CRM_Core_Config::singleton()->includeWildCardInName && (substr($value, 0, 1) != '%')) {
return "%$value%";
$value = "%$value";
Copy link
Member

@totten totten Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, it wrapped the string with %s on both sides. After, it only prepends %.

My memory of this codepath is a bit stale -- but wouldn't that be a substantive change in the search behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the following two lines (6314-6315) which add the trailing '%' if it does not already exist.

}
else {
return "$value%";
if (substr($value, -1, 1) != '%') {
$value = "$value%";
}
}
else {
return "$value";
}
return "$value";
}

/**
Expand Down
6 changes: 5 additions & 1 deletion CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ protected function convertTextStringsToUseLikeOperator() {
foreach ($fields as $fieldName => $field) {
if (!empty($this->_formValues[$fieldName]) && empty($field['options']) && empty($field['pseudoconstant'])) {
if (in_array($field['type'], [CRM_Utils_Type::T_STRING, CRM_Utils_Type::T_TEXT])) {
$this->_formValues[$fieldName] = ['LIKE' => CRM_Contact_BAO_Query::getWildCardedValue(TRUE, 'LIKE', trim($this->_formValues[$fieldName]))];
$val = $this->_formValues[$fieldName];
if (is_array($val)) {
$val = $val['LIKE'];
}
$this->_formValues[$fieldName] = ['LIKE' => CRM_Contact_BAO_Query::getWildCardedValue(TRUE, 'LIKE', trim($val))];
}
}
}
Expand Down