From 2297a28d24351e8f13e0ff5c010886017829b7ee Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 12 Aug 2020 09:38:05 +1200 Subject: [PATCH] dev/core#1934 fix regression on merging contacts with settings using contact_id This is an interim fix to a reported regression. I'll look at more carefully in master when time permits --- CRM/Dedupe/Merger.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index ca548fba2d0d..3cc6e233f202 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -541,6 +541,17 @@ public static function moveContactBelongings($mergeHandler, $tables, $tableOpera 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])) {