dev/core#1934 fix regression on merging contacts with settings using contact_id
authoreileen <emcnaughton@wikimedia.org>
Tue, 11 Aug 2020 21:38:05 +0000 (09:38 +1200)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 11 Aug 2020 23:27:21 +0000 (09:27 +1000)
This is an interim fix to a reported regression. I'll look at more carefully in master when time permits

CRM/Dedupe/Merger.php

index 74669495b4e596984be8ff630f6bdf19f0b50194..86217e04979f2ce3cab3c65b74aa5dd4cec04f92 100644 (file)
@@ -541,6 +541,17 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
         continue;
       }
 
+      if ($table === 'civicrm_setting') {
+        // Per https://lab.civicrm.org/dev/core/-/issues/1934
+        // Note this line is not unit tested as yet as a quick-fix for a regression
+        // but it would be better to do a SELECT request & only update if needed (as a general rule
+        // more selects & less UPDATES will result in less deadlocks while de-duping.
+        // Note the delete is not important here - it can stay with the deleted contact on the
+        // off chance they get restored.
+        $sqls[] = "UPDATE IGNORE civicrm_setting SET contact_id = $mainId 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])) {