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

Search Builder fails with an error when searching for State if the location type differs from the display name. #13313

Merged
merged 2 commits into from
Dec 19, 2018

Conversation

kainuk
Copy link
Contributor

@kainuk kainuk commented Dec 18, 2018

Overview

Search Builder fails with an error when searching for State if the location type differs from the display name.

To reproduce

Before

To reproduce

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.

@civibot
Copy link

civibot bot commented Dec 18, 2018

(Standard links)

@civibot civibot bot added the master label Dec 18, 2018
@kainuk kainuk changed the title Fix for issue 607 Search Builder fails with an error when searching for State if the location type differs from the display name. Dec 18, 2018
@@ -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])) {
Copy link
Contributor

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]);

Copy link
Contributor Author

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.

Copy link
Member

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');

@monishdeb
Copy link
Member

The patch successfully fixes the issue. Here's the screencasts:

BEFORE

before1

AFTER

after

@monishdeb
Copy link
Member

monishdeb commented Dec 19, 2018

Merging on basis of:

@monishdeb monishdeb merged commit ef5c5cd into civicrm:master Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants