From 59041f88b879768c296a92606b9ce4176b2393d2 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 13 Jul 2020 23:09:34 +1200 Subject: [PATCH] Fix dedupe on same-activity-connection --- CRM/Dedupe/Merger.php | 6 ++++++ tests/phpunit/api/v3/JobTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 9bdc157ac1..74669495b4 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -535,6 +535,12 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m continue; } + if ($table === 'civicrm_activity_contact') { + $sqls[] = "UPDATE IGNORE civicrm_activity_contact SET contact_id = $mainId WHERE contact_id = $otherId"; + $sqls[] = "DELETE FROM civicrm_activity_contact WHERE contact_id = $otherId"; + continue; + } + // use UPDATE IGNORE + DELETE query pair to skip on situations when // there's a UNIQUE restriction on ($field, some_other_field) pair if (isset($cidRefs[$table])) { diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index f6a9bfb27c..9eb857ff85 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -594,6 +594,16 @@ class api_v3_JobTest extends CiviUnitTestCase { $this->callAPISuccess('Job', 'process_batch_merge', ['mode' => 'safe']); } + /** + * Test that we handle cache entries without clashes. + */ + public function testMergeSharedActivity() { + $contactID = $this->individualCreate(); + $contact2ID = $this->individualCreate(); + $activityID = $this->activityCreate(['target_contact_id' => [$contactID, $contact2ID]]); + $this->callAPISuccess('Job', 'process_batch_merge', ['mode' => 'safe']); + } + /** * Test the decisions made for addresses when merging. * -- 2.25.1