Fix dedupe on same-activity-connection
authoreileen <emcnaughton@wikimedia.org>
Mon, 13 Jul 2020 11:09:34 +0000 (23:09 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 13 Jul 2020 11:09:51 +0000 (23:09 +1200)
CRM/Dedupe/Merger.php
tests/phpunit/api/v3/JobTest.php

index 9bdc157ac1c4a72a673d9454adf2fc5fe9954705..74669495b4e596984be8ff630f6bdf19f0b50194 100644 (file)
@@ -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])) {
index f6a9bfb27c2b705da9cbbf04397303568babbab7..9eb857ff85d9706c41e547577c39ed00b288d110 100644 (file)
@@ -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.
    *