X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FDedupe%2FBAO%2FQueryBuilder.php;h=1137be40c940e0a36698caf275e0a3bac0cab7b8;hb=2972cd189ed39ab3ef1e3cb91ed4f6bdc64ebb1e;hp=484ce391c64ded690b90940b958f06911a3513da;hpb=674cb8b854f6008090d4dcce9372ee76346a198f;p=civicrm-core.git diff --git a/CRM/Dedupe/BAO/QueryBuilder.php b/CRM/Dedupe/BAO/QueryBuilder.php index 484ce391c6..1137be40c9 100644 --- a/CRM/Dedupe/BAO/QueryBuilder.php +++ b/CRM/Dedupe/BAO/QueryBuilder.php @@ -3,6 +3,7 @@ * Class CRM_Dedupe_BAO_QueryBuilder */ class CRM_Dedupe_BAO_QueryBuilder { + /** * @param $rg * @param string $strID1 @@ -22,4 +23,28 @@ class CRM_Dedupe_BAO_QueryBuilder { } } + /** + * If a contact list is specified then adjust the query to ensure one contact is in that list. + * + * Doing an OR join here will lead to a server-killing unindexed query. However, a union will + * perform better. + * + * @param array $contactList + * @param string $query + * @param string $strID1 + * @param string $strID2 + * + * @return string + */ + protected static function filterQueryByContactList(array $contactList, $query, $strID1 = 'contact1.id', $strID2 = 'contact2.id') { + if (empty($contactList)) { + return $query . " AND ($strID1 < $strID2)"; + } + $contactIDs = implode(',', $contactList); + return "$query AND $strID1 IN ($contactIDs) AND $strID1 > $strID2 + UNION $query AND $strID1 > $strID2 AND $strID2 IN ($contactIDs) AND $strID1 NOT IN ($contactIDs) + "; + + } + }