3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class CRM_Dedupe_BAO_QueryBuilder_IndividualUnsupervised
31 class CRM_Dedupe_BAO_QueryBuilder_IndividualUnsupervised
extends CRM_Dedupe_BAO_QueryBuilder
{
38 static function record($rg) {
39 $civicrm_email = CRM_Utils_Array
::value('civicrm_email', $rg->params
, array());
42 1 => array(CRM_Utils_Array
::value('email', $civicrm_email, ''), 'String'),
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),
60 static function internal($rg) {
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);
75 * An alternative version which might perform a lot better
76 * than the above. Will need to do some testing
78 static function internalOptimized($rg) {
80 CREATE TEMPORARY TABLE emails (
88 CRM_Core_DAO
::executeQuery($sql);
92 SELECT email1.email as email, email1.contact_id as contact_id1, email2.contact_id as contact_id2
93 FROM civicrm_email as email1
94 JOIN civicrm_email as email2 USING (email)
95 WHERE email1.contact_id < email2.contact_id
96 AND " . self
::internalFilters($rg, "email1.contact_id", "email2.contact_id" );
97 CRM_Core_DAO
::executeQuery($sql);
100 SELECT contact_id1 as id1, contact_id2 as id2, {$rg->threshold} as weight
102 JOIN civicrm_contact as contact1 on contact1.id=contact_id1
103 JOIN civicrm_contact as contact2 on contact2.id=contact_id2
104 WHERE contact1.contact_type='Individual'
105 AND contact2.contact_type='Individual'
106 AND " . self
::internalFilters($rg);
108 return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query);