Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
03e04002 | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
03e04002 | 5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
6a488035 TO |
27 | class CRM_Dedupe_BAO_QueryBuilder_IndividualUnsupervised extends CRM_Dedupe_BAO_QueryBuilder { |
28 | ||
29 | static function record($rg) { | |
30 | $civicrm_email = CRM_Utils_Array::value('civicrm_email', $rg->params, array()); | |
31 | ||
32 | $params = array( | |
33 | 1 => array(CRM_Utils_Array::value('email', $civicrm_email, ''), 'String'), | |
34 | ); | |
35 | ||
36 | return array( | |
37 | "civicrm_contact.{$rg->name}.{$rg->threshold}" => CRM_Core_DAO::composeQuery(" | |
38 | SELECT contact.id as id1, {$rg->threshold} as weight | |
39 | FROM civicrm_contact as contact | |
40 | JOIN civicrm_email as email ON email.contact_id=contact.id | |
41 | WHERE contact_type = 'Individual' | |
42 | AND email = %1", $params, TRUE), | |
43 | ); | |
44 | } | |
45 | ||
46 | static function internal($rg) { | |
47 | $query = " | |
48 | SELECT contact1.id as id1, contact2.id as id2, {$rg->threshold} as weight | |
49 | FROM civicrm_contact as contact1 | |
50 | JOIN civicrm_email as email1 ON email1.contact_id=contact1.id | |
51 | JOIN civicrm_contact as contact2 | |
52 | JOIN civicrm_email as email2 ON | |
53 | email2.contact_id=contact2.id AND | |
54 | email1.email=email2.email | |
55 | WHERE contact1.contact_type = 'Individual' | |
56 | AND " . self::internalFilters($rg); | |
57 | return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query); | |
58 | } | |
59 | ||
60 | /** | |
61 | * An alternative version which might perform a lot better | |
62 | * than the above. Will need to do some testing | |
63 | */ | |
64 | static function internalOptimized($rg) { | |
65 | $sql = " | |
66 | CREATE TEMPORARY TABLE emails ( | |
67 | email varchar(255), | |
68 | contact_id1 int, | |
69 | contact_id2 int, | |
70 | INDEX(contact_id1), | |
71 | INDEX(contact_id2) | |
72 | ) ENGINE=MyISAM | |
73 | "; | |
74 | CRM_Core_DAO::executeQuery($sql); | |
75 | ||
76 | $sql = " | |
77 | INSERT INTO emails | |
78 | SELECT email1.email as email, email1.contact_id as contact_id1, email2.contact_id as contact_id2 | |
79 | FROM civicrm_email as email1 | |
80 | JOIN civicrm_email as email2 USING (email) | |
81 | WHERE email1.contact_id < email2.contact_id | |
82 | AND " . self::internalFilters($rg, "email1.contact_id", "email2.contact_id" ); | |
83 | CRM_Core_DAO::executeQuery($sql); | |
84 | ||
85 | $query = " | |
86 | SELECT contact_id1 as id1, contact_id2 as id2, {$rg->threshold} as weight | |
87 | FROM emails | |
88 | JOIN civicrm_contact as contact1 on contact1.id=contact_id1 | |
89 | JOIN civicrm_contact as contact2 on contact2.id=contact_id2 | |
03e04002 | 90 | WHERE contact1.contact_type='Individual' |
6a488035 TO |
91 | AND contact2.contact_type='Individual' |
92 | AND " . self::internalFilters($rg); | |
93 | ||
94 | return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query); | |
95 | } | |
96 | }; | |
97 | ||
98 | ||
99 |