From: Darrick Servis Date: Sat, 14 May 2022 22:07:35 +0000 (-0700) Subject: Text user supplied dedupe rule is used during import. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3050997a3fab4cfdf2fb14926d18e307df9c9d89;p=civicrm-core.git Text user supplied dedupe rule is used during import. --- diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 5b72b261cb..e57df876cc 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1925,6 +1925,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } $checkParams = ['check_permissions' => FALSE, 'match' => $params]; $checkParams['match']['contact_type'] = $this->_contactType; + $checkParams['dedupe_rule_id'] = $this->_dedupeRuleGroupID ?? NULL; $possibleMatches = civicrm_api3('Contact', 'duplicatecheck', $checkParams); if (!$extIDMatch) { diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 4a4ddfbe12..028f3d7598 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -120,6 +120,112 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->callAPISuccessGetSingle('Contact', $originalValues); } + /** + * Test import parser will update based on a custom rule match. + * + * In this case the contact has no external identifier. + * + * @throws \API_Exception + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + */ + public function testImportParserWithUpdateWithCustomRule(): void { + $this->createCustomGroupWithFieldsOfAllTypes(); + + $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [ + 'contact_type' => 'Individual', + 'threshold' => 10, + 'used' => 'General', + 'name' => 'TestRule', + 'title' => 'TestRule', + 'is_reserved' => 0, + ]); + $this->callAPISuccess('Rule', 'create', [ + 'dedupe_rule_group_id' => $ruleGroup['id'], + 'rule_table' => $this->getCustomGroupTable(), + 'rule_weight' => 10, + 'rule_field' => $this->getCustomFieldColumnName('text'), + ]); + + $extra = [ + $this->getCustomFieldName('select_string') => 'Yellow', + $this->getCustomFieldName('text') => 'Duplicate', + ]; + + [$originalValues, $result] = $this->setUpBaseContact($extra); + + $contactValues = [ + 'first_name' => 'Tim', + 'last_name' => 'Cook', + 'email' => 'tim.cook@apple.com', + 'nick_name' => 'Steve', + $this->getCustomFieldName('select_string') => 'Red', + $this->getCustomFieldName('text') => 'Duplicate', + ]; + + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [], NULL, $ruleGroup['id']); + $contactValues['id'] = $result['id']; + $this->assertEquals('R', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => $this->getCustomFieldName('select_string')])); + $this->callAPISuccessGetSingle('Contact', $contactValues); + + $foundDupes = CRM_Dedupe_Finder::dupes($ruleGroup['id']); + $this->assertCount(0, $foundDupes); + } + + /** + * Test import parser will update based on a custom rule match. + * + * In this case the contact has no external identifier. + * + * @throws \API_Exception + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + */ + public function testImportParserWithUpdateWithCustomRuleNoExternalIDMatch(): void { + $this->createCustomGroupWithFieldsOfAllTypes(); + + $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [ + 'contact_type' => 'Individual', + 'threshold' => 10, + 'used' => 'General', + 'name' => 'TestRule', + 'title' => 'TestRule', + 'is_reserved' => 0, + ]); + $this->callAPISuccess('Rule', 'create', [ + 'dedupe_rule_group_id' => $ruleGroup['id'], + 'rule_table' => $this->getCustomGroupTable(), + 'rule_weight' => 10, + 'rule_field' => $this->getCustomFieldColumnName('text'), + ]); + + $extra = [ + $this->getCustomFieldName('select_string') => 'Yellow', + $this->getCustomFieldName('text') => 'Duplicate', + 'external_identifier' => 'ext-2', + ]; + + [$originalValues, $result] = $this->setUpBaseContact($extra); + + $contactValues = [ + 'first_name' => 'Tim', + 'last_name' => 'Cook', + 'email' => 'tim.cook@apple.com', + 'nick_name' => 'Steve', + 'external_identifier' => 'ext-1', + $this->getCustomFieldName('select_string') => 'Red', + $this->getCustomFieldName('text') => 'Duplicate', + ]; + + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [], NULL, $ruleGroup['id']); + $contactValues['id'] = $result['id']; + $this->assertEquals('R', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => $this->getCustomFieldName('select_string')])); + $this->callAPISuccessGetSingle('Contact', $contactValues); + + $foundDupes = CRM_Dedupe_Finder::dupes($ruleGroup['id']); + $this->assertCount(0, $foundDupes); + } + /** * Test import parser will update contacts with an external identifier. *