Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
03e04002 | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
03e04002 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
03e04002 | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
4c6ce474 EM |
27 | |
28 | /** | |
29 | * Class CRM_Dedupe_BAO_QueryBuilder_IndividualUnsupervised | |
30 | */ | |
6a488035 TO |
31 | class CRM_Dedupe_BAO_QueryBuilder_IndividualUnsupervised extends CRM_Dedupe_BAO_QueryBuilder { |
32 | ||
e0ef6999 EM |
33 | /** |
34 | * @param $rg | |
35 | * | |
36 | * @return array | |
37 | */ | |
00be9182 | 38 | public static function record($rg) { |
6a488035 TO |
39 | $civicrm_email = CRM_Utils_Array::value('civicrm_email', $rg->params, array()); |
40 | ||
41 | $params = array( | |
42 | 1 => array(CRM_Utils_Array::value('email', $civicrm_email, ''), 'String'), | |
43 | ); | |
44 | ||
45 | return array( | |
46 | "civicrm_contact.{$rg->name}.{$rg->threshold}" => CRM_Core_DAO::composeQuery(" | |
47 | SELECT contact.id as id1, {$rg->threshold} as weight | |
48 | FROM civicrm_contact as contact | |
49 | JOIN civicrm_email as email ON email.contact_id=contact.id | |
50 | WHERE contact_type = 'Individual' | |
51 | AND email = %1", $params, TRUE), | |
52 | ); | |
53 | } | |
54 | ||
e0ef6999 EM |
55 | /** |
56 | * @param $rg | |
57 | * | |
58 | * @return array | |
59 | */ | |
00be9182 | 60 | public static function internal($rg) { |
6a488035 TO |
61 | $query = " |
62 | SELECT contact1.id as id1, contact2.id as id2, {$rg->threshold} as weight | |
63 | FROM civicrm_contact as contact1 | |
64 | JOIN civicrm_email as email1 ON email1.contact_id=contact1.id | |
65 | JOIN civicrm_contact as contact2 | |
66 | JOIN civicrm_email as email2 ON | |
67 | email2.contact_id=contact2.id AND | |
68 | email1.email=email2.email | |
69 | WHERE contact1.contact_type = 'Individual' | |
70 | AND " . self::internalFilters($rg); | |
71 | return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query); | |
72 | } | |
73 | ||
74 | /** | |
75 | * An alternative version which might perform a lot better | |
76 | * than the above. Will need to do some testing | |
ad37ac8e | 77 | * |
78 | * @param string $rg | |
79 | * | |
80 | * @return array | |
6a488035 | 81 | */ |
00be9182 | 82 | public static function internalOptimized($rg) { |
6a488035 TO |
83 | $sql = " |
84 | CREATE TEMPORARY TABLE emails ( | |
85 | email varchar(255), | |
86 | contact_id1 int, | |
87 | contact_id2 int, | |
88 | INDEX(contact_id1), | |
89 | INDEX(contact_id2) | |
75f1cd78 | 90 | ) ENGINE=InnoDB |
6a488035 TO |
91 | "; |
92 | CRM_Core_DAO::executeQuery($sql); | |
93 | ||
94 | $sql = " | |
95 | INSERT INTO emails | |
96 | SELECT email1.email as email, email1.contact_id as contact_id1, email2.contact_id as contact_id2 | |
97 | FROM civicrm_email as email1 | |
98 | JOIN civicrm_email as email2 USING (email) | |
99 | WHERE email1.contact_id < email2.contact_id | |
481a74f4 | 100 | AND " . self::internalFilters($rg, "email1.contact_id", "email2.contact_id"); |
6a488035 TO |
101 | CRM_Core_DAO::executeQuery($sql); |
102 | ||
103 | $query = " | |
104 | SELECT contact_id1 as id1, contact_id2 as id2, {$rg->threshold} as weight | |
105 | FROM emails | |
106 | JOIN civicrm_contact as contact1 on contact1.id=contact_id1 | |
107 | JOIN civicrm_contact as contact2 on contact2.id=contact_id2 | |
03e04002 | 108 | WHERE contact1.contact_type='Individual' |
6a488035 TO |
109 | AND contact2.contact_type='Individual' |
110 | AND " . self::internalFilters($rg); | |
111 | ||
112 | return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query); | |
113 | } | |
96025800 | 114 | |
353ffa53 | 115 | } |