From 30415e032f8f5f190fe667cdea63b67772eb1b94 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 30 Dec 2016 18:13:30 +1300 Subject: [PATCH] CRM-19811 fix one instance of referring to LOWER() & comment others. I have tested & removed the current_employer reference & added notes to other references to LOWER. I will track down & remove the one relating to credit notes in the next round --- CRM/Contact/BAO/Query.php | 14 +++++++++++--- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index cb9a448a34..bfe7173e00 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2187,13 +2187,11 @@ class CRM_Contact_BAO_Query { $this->_qill[$grouping][] = "$field[title] $op \"$value\""; } elseif ($name === 'current_employer') { - $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $op = 'LIKE'; $value = self::getWildCardedValue($wildcard, $op, $value); } - $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name"; - $ceWhereClause = self::buildClause($wc, $op, + $ceWhereClause = self::buildClause("contact_a.organization_name", $op, $value ); $ceWhereClause .= " AND contact_a.contact_type = 'Individual'"; @@ -2266,10 +2264,12 @@ class CRM_Contact_BAO_Query { } else { if ($tableName == 'civicrm_contact') { + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $fieldName = "LOWER(contact_a.{$fieldName})"; } else { if ($op != 'IN' && !is_numeric($value) && !is_array($value)) { + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $fieldName = "LOWER({$field['where']})"; } else { @@ -3335,13 +3335,16 @@ WHERE $smartGroupClause $fieldsub = array(); $value = "'" . self::getWildCardedValue($wildcard, $op, $value) . "'"; if ($fieldName == 'sort_name') { + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $wc = self::caseImportant($op) ? "LOWER(contact_a.sort_name)" : "contact_a.sort_name"; } else { + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $wc = self::caseImportant($op) ? "LOWER(contact_a.display_name)" : "contact_a.display_name"; } $fieldsub[] = " ( $wc $op $value )"; if ($config->includeNickNameInName) { + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $wc = self::caseImportant($op) ? "LOWER(contact_a.nick_name)" : "contact_a.nick_name"; $fieldsub[] = " ( $wc $op $value )"; } @@ -3478,6 +3481,7 @@ WHERE $smartGroupClause $value = "%{$value}%"; } $op = 'LIKE'; + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $this->_where[$grouping][] = self::buildClause('LOWER(civicrm_address.street_address)', $op, $value, 'String'); $this->_qill[$grouping][] = ts('Street') . " $op '$n'"; } @@ -3514,6 +3518,7 @@ WHERE $smartGroupClause else { $value = strtolower($n); + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $this->_where[$grouping][] = self::buildClause('LOWER(civicrm_address.street_number)', $op, $value, 'String'); $this->_qill[$grouping][] = ts('Street Number') . " $op '$n'"; } @@ -5629,6 +5634,8 @@ AND displayRelType.is_active = 1 } /** + * See CRM-19811 for why this is database hurty without apparent benefit. + * * @param $op * * @return bool @@ -5706,6 +5713,7 @@ AND displayRelType.is_active = 1 } } else { + // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}"; } if (in_array($name, $pseudoFields)) { diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 2c5a6d8e82..8bffbf8c80 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -247,6 +247,21 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { CRM_Contact_BAO_GroupContactCache::load($group, TRUE); } + /** + * Test searches are case insensitive. + */ + public function testCaseInsensitive() { + $orgID = $this->organizationCreate(array('organization_name' => 'BOb')); + $this->callAPISuccess('Contact', 'create', array('display_name' => 'Minnie Mouse', 'employer_id' => $orgID, 'contact_type' => 'Individual')); + $searchParams = array(array('current_employer', '=', 'bob', 0, 1)); + $query = new CRM_Contact_BAO_Query($searchParams); + $result = $query->apiQuery($searchParams); + $this->assertEquals(1, count($result[0])); + $contact = reset($result[0]); + $this->assertEquals('Minnie Mouse', $contact['display_name']); + $this->assertEquals('BOb', $contact['current_employer']); + } + /** * Test smart groups with non-numeric don't fail on equal queries. * -- 2.25.1