CRM-18522 tests to attempt to reproduce the reported sql error.
[civicrm-core.git] / CRM / Dedupe / BAO / RuleGroup.php
index 1616392f6d04371c248867deb714c4586d5834a0..a6ea3542fcd86b6ddca962c7d46d61926ddadac3 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  * $Id$
  *
  */
@@ -44,6 +44,15 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
    */
   var $contactIds = array();
 
+  /**
+   * Set the contact IDs to restrict the dedupe to.
+   *
+   * @param array $contactIds
+   */
+  public function setContactIds($contactIds) {
+    $this->contactIds = $contactIds;
+  }
+
   /**
    * Params to dedupe against (queries against the whole contact set otherwise)
    */
@@ -77,6 +86,7 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
         'addressee.label' => 'civicrm_contact.addressee_id',
         'email_greeting.label' => 'civicrm_contact.email_greeting_id',
         'postal_greeting.label' => 'civicrm_contact.postal_greeting_id',
+        'civicrm_phone.phone' => 'civicrm_phone.phone_numeric',
       );
       // the table names we support in dedupe rules - a filter for importableFields()
       $supportedTables = array(
@@ -141,10 +151,8 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
     if ($this->is_reserved &&
       CRM_Utils_File::isIncludable("CRM/Dedupe/BAO/QueryBuilder/{$this->name}.php")
     ) {
-      include_once "CRM/Dedupe/BAO/QueryBuilder/{$this->name}.php";
-      $class = "CRM_Dedupe_BAO_QueryBuilder_{$this->name}";
       $command = empty($this->params) ? 'internal' : 'record';
-      $queries = call_user_func(array($class, $command), $this);
+      $queries = call_user_func(array("CRM_Dedupe_BAO_QueryBuilder_{$this->name}", $command), $this);
     }
     else {
       // All other rule groups have queries generated by the member dedupe
@@ -174,8 +182,8 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
     // if there are no rules in this rule group
     // add an empty query fulfilling the pattern
     if (!$queries) {
-      $queries = array('SELECT 0 id1, 0 id2, 0 weight LIMIT 0');
       $this->noRules = TRUE;
+      return array();
     }
 
     return $queries;
@@ -467,4 +475,27 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
     return $result;
   }
 
+
+  /**
+   * Get the cached contact type for a particular rule group.
+   *
+   * @param int $rule_group_id
+   *
+   * @return string
+   */
+  public static function getContactTypeForRuleGroup($rule_group_id) {
+    if (!isset(\Civi::$statics[__CLASS__]) || !isset(\Civi::$statics[__CLASS__]['rule_groups'])) {
+      \Civi::$statics[__CLASS__]['rule_groups'] = array();
+    }
+    if (empty(\Civi::$statics[__CLASS__]['rule_groups'][$rule_group_id])) {
+      \Civi::$statics[__CLASS__]['rule_groups'][$rule_group_id]['contact_type'] = CRM_Core_DAO::getFieldValue(
+        'CRM_Dedupe_DAO_RuleGroup',
+        $rule_group_id,
+        'contact_type'
+      );
+    }
+
+    return \Civi::$statics[__CLASS__]['rule_groups'][$rule_group_id]['contact_type'];
+  }
+
 }