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
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
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

$lType = $locationType[$locType[1]];
}
Expand Down
45 changes: 45 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,51 @@ public function testSearchPrimaryLocTypes() {
}
}

/**
* Test created to prove failure of search on state when location
* display name is different form location name (issue 607)
*/
public function testSearchOtherLocationUpperLower() {

$params = [
0 => [
0 => 'state_province-4',
1 => 'IS NOT EMPTY',
2 => '',
3 => 1,
4 => 0,
],
];
$returnProperties = [
'contact_type' => 1,
'contact_sub_type' => 1,
'sort_name' => 1,
'location' => [
'other' => [
'location_type' => 4,
'state_province' => 1,
],
],
];

// update with the api does not work because it updates both the name and the
// the display_name. Plain SQL however does the job
CRM_Core_DAO::executeQuery('update civicrm_location_type set name=%2 where id=%1',
[
1 => [4, 'Integer'],
2 => ['other', 'String'],
]);

$queryObj = new CRM_Contact_BAO_Query($params, $returnProperties);

$resultDAO = $queryObj->searchQuery(0, 0, NULL,
FALSE, FALSE,
FALSE, FALSE,
FALSE);
$resultDAO->fetch();
}


/**
* CRM-14263 search builder failure with search profile & address in criteria.
*
Expand Down