From 9742d8f3b2dbcffae08137055bf4f03626feec13 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 29 Dec 2019 07:22:34 +1100 Subject: [PATCH] dev/core#183 Ensure that having a rule where each field is the same weight with the threshold being the total sum of the weights does not cause a fatal error when searching for dupes --- CRM/Dedupe/BAO/RuleGroup.php | 2 ++ tests/phpunit/CRM/Dedupe/DedupeFinderTest.php | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CRM/Dedupe/BAO/RuleGroup.php b/CRM/Dedupe/BAO/RuleGroup.php index 8eb26212ed..0853368446 100644 --- a/CRM/Dedupe/BAO/RuleGroup.php +++ b/CRM/Dedupe/BAO/RuleGroup.php @@ -234,6 +234,8 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup { $query = array_shift($tableQueries); if ($searchWithinDupes) { + // drop dedupe_copy table just in case if its already there. + $dedupeCopyTemporaryTableObject->drop(); // get prepared to search within already found dupes if $searchWithinDupes flag is set $dedupeCopyTemporaryTableObject->createWithQuery("SELECT * FROM {$this->temporaryTables['dedupe']} WHERE weight >= {$weightSum}"); diff --git a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php index b0318c12a0..0666a70854 100644 --- a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php +++ b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php @@ -140,6 +140,33 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { } + /** + * Test rule from Richard + */ + public function testRuleThreeContactFieldsEqualWeightWIthThresholdtheTotalSumOfAllWeight() { + $this->setupForGroupDedupe(); + + $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [ + 'contact_type' => 'Individual', + 'threshold' => 30, + 'used' => 'General', + 'name' => 'TestRule', + 'title' => 'TestRule', + 'is_reserved' => 0, + ]); + + foreach (['first_name', 'last_name', 'birth_date'] as $field) { + $rules[$field] = $this->callAPISuccess('Rule', 'create', [ + 'dedupe_rule_group_id' => $ruleGroup['id'], + 'rule_table' => 'civicrm_contact', + 'rule_weight' => 10, + 'rule_field' => $field, + ]); + } + $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); + $this->assertEquals(1, count($foundDupes)); + } + /** * Test a custom rule with a non-default field. */ -- 2.25.1