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/98) FGB Searching by any Address fields with location type other than primary throw DB error #12074

Merged
merged 1 commit into from
May 3, 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
14 changes: 13 additions & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,13 @@ public function searchQuery(
$additionalFromClause = NULL, $skipOrderAndLimit = FALSE
) {

// In this case we are expecting the search query to return all the first single letter characters of contacts ONLY,
// but when FGB (FULL_GROUP_BY_MODE) is enabled MySQL expect the columns present in GROUP BY must be present in SELECT clause
// and that results into error and needless to have other columns. In order to resolve this disable FGB to fulfill both the cases
if ($sortByChar) {
CRM_Core_DAO::disableFullGroupByMode();
}

if ($includeContactIds) {
$this->_includeContactIds = TRUE;
$this->_whereClause = $this->whereClause();
Expand Down Expand Up @@ -4899,7 +4906,7 @@ public function searchQuery(

if (!empty($groupByCols)) {
// It doesn't matter to include columns in SELECT clause, which are present in GROUP BY when we just want the contact IDs
if (!$groupContacts) {
if (!$groupContacts && !$sortByChar) {
$select = self::appendAnyValueToSelect($this->_select, $groupByCols, 'GROUP_CONCAT');
}
$groupBy = " GROUP BY " . implode(', ', $groupByCols);
Expand Down Expand Up @@ -4940,6 +4947,11 @@ public function searchQuery(
}

$dao = CRM_Core_DAO::executeQuery($query);

if ($sortByChar) {
CRM_Core_DAO::reenableFullGroupByMode();
}

if ($groupContacts) {
$ids = array();
while ($dao->fetch()) {
Expand Down
5 changes: 4 additions & 1 deletion tests/phpunit/CRM/Contact/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ public function testSelectorQuery($dataSet) {
}
// Ensure that search builder return individual contact as per criteria
if (!empty($dataSet['context'] == 'builder')) {
$contactID = $this->individualCreate();
$contactID = $this->individualCreate(['first_name' => 'James', 'last_name' => 'Bond']);
$rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 50, '');
$this->assertEquals(1, count($rows));
$sortChar = $selector->alphabetQuery()->fetchAll();
// sort name is stored in '<last_name>, <first_name>' format, as per which the first character would be B of Bond
$this->assertEquals('B', $sortChar[0]['sort_name']);
$this->assertEquals($contactID, key($rows));
}
}
Expand Down