From 0ca748fb77dea859bc772114c3aa960f1a2f56ed Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 2 Dec 2019 12:51:34 -0500 Subject: [PATCH] enable matching on contact phone when importing contributions --- CRM/Dedupe/BAO/Rule.php | 6 +++- CRM/Dedupe/BAO/RuleGroup.php | 6 +++- .../Import/Parser/ContributionTest.php | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CRM/Dedupe/BAO/Rule.php b/CRM/Dedupe/BAO/Rule.php index 6ff97260ee..599c1cac31 100644 --- a/CRM/Dedupe/BAO/Rule.php +++ b/CRM/Dedupe/BAO/Rule.php @@ -211,7 +211,11 @@ class CRM_Dedupe_BAO_Rule extends CRM_Dedupe_DAO_Rule { $ruleBao->find(); $ruleFields = []; while ($ruleBao->fetch()) { - $ruleFields[] = $ruleBao->rule_field; + $field_name = $ruleBao->rule_field; + if ($field_name == 'phone_numeric') { + $field_name = 'phone'; + } + $ruleFields[] = $field_name; } return $ruleFields; } diff --git a/CRM/Dedupe/BAO/RuleGroup.php b/CRM/Dedupe/BAO/RuleGroup.php index 8eb26212ed..8838e8783e 100644 --- a/CRM/Dedupe/BAO/RuleGroup.php +++ b/CRM/Dedupe/BAO/RuleGroup.php @@ -429,7 +429,11 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup { $ruleBao->find(); $ruleFields = []; while ($ruleBao->fetch()) { - $ruleFields[$ruleBao->rule_field] = $ruleBao->rule_weight; + $field_name = $ruleBao->rule_field; + if ($field_name == 'phone_numeric') { + $field_name = 'phone'; + } + $ruleFields[$field_name] = $ruleBao->rule_weight; } return [$ruleFields, $rgBao->threshold]; diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 02e42c062b..8182fe9e2e 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -179,6 +179,40 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { $this->assertEquals('20191020000000', $formatted[$this->getCustomFieldName('date')]); } + /** + * Test phone is included if it is part of dedupe rule. + * + * @throws \CRM_Core_Exception + */ + public function testPhoneMatchOnContact() { + // Update existing unsupervised rule, change to general. + $unsupervisedRuleGroup = $this->callApiSuccess('RuleGroup', 'getsingle', [ + 'used' => 'Unsupervised', + 'contact_type' => 'Individual' + ]); + $this->callApiSuccess('RuleGroup', 'create', [ + 'id' => $unsupervisedRuleGroup['id'], + 'used' => 'General' + ]); + + // Create new unsupervised rule with Phone field. + $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [ + 'contact_type' => 'Individual', + 'threshold' => 10, + 'used' => 'Unsupervised', + 'name' => 'MatchingPhone', + 'title' => 'Matching Phone', + 'is_reserved' => 0, + ]); + $this->callAPISuccess('Rule', 'create', [ + 'dedupe_rule_group_id' => $ruleGroup['id'], + 'rule_table' => 'civicrm_phone', + 'rule_weight' => 10, + 'rule_field' => 'phone_numeric', + ]); + $fields = CRM_Contribute_BAO_Contribution::importableFields(); + $this->assertTrue(array_key_exists('phone', $fields)); + } /** * Run the import parser. * -- 2.25.1