-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Search Builder fails with an error when searching for State if the location type differs from the display name. #13313
Conversation
(Standard links)
|
@@ -2130,7 +2130,7 @@ public function restWhere(&$values) { | |||
|
|||
$setTables = TRUE; | |||
|
|||
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); | |||
$locationType = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); | |||
if (isset($locType[1]) && is_numeric($locType[1])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same thing could be achieved with:
CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', [], 'validate');
I'm not sure which of CRM_Core_PseudoConstant::get
and CRM_Core_DAO_Address::buildOptions` is preferred - @eileenmcnaughton ??
In this case, I think you could further simplify this to something like:
CRM_Core_PseudoConstant::getName('CRM_Core_DAO_Address', 'location_type_id', $locType[1]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe buildOptions
is not the best solution, but I chose it to be the same as the code used on line 2790.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire I think its ok to use buildOptions in here as we are doing in other places too:
CRM//Contact/Selector.php:419: $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate');
CRM//Contact/BAO/Query.php:1016: $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate');
CRM//Contact/BAO/Query.php:2371: $locationType = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate');
CRM//Contact/BAO/Query.php:2790: $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate');
CRM//Core/BAO/Mapping.php:1132: $locationTypes = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate');
Overview
Search Builder fails with an error when searching for State if the location type differs from the display name.
To reproduce
The search ends with a DB Error - Syntax Error
Before
To reproduce
The search ends with a DB Error - Syntax Error
After
The same as above except that the search now gives a result.
Technical Details
The cause of the problem is that locationtypes can be retrieved on two different ways in CiviCRM e.g.
CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate');
and
CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id')
When name and display_name have a different case these functions return different results.
My solution is to replace the second with the first.
A test is added to the PR. It fails with unknown variable. I do not know how to catch it
Comments
Also on gitlab (https://lab.civicrm.org/dev/core/issues/607).
In the test database name and display are the same. The effect is that this kind of bug is not catched. Tip for implementers. Take care that name and display name are always the same.