Skip to content

Commit

Permalink
[WIP] test removing the update ignore to see what fails.
Browse files Browse the repository at this point in the history
This is fundamentally risky - we don't know all the reasons why UPDATE IGNORE could fail & hence
we don't know what could be deleted when it does. Note that I came across the following as a deadlock-causing query

 DELETE FROM civicrm_contact WHERE  primary_contact_id = 41372076

and am altering the test to look for whether UPDATE IGNORE is in fact needed as the above looks risky
as well as increasing our lock queries
  • Loading branch information
eileenmcnaughton committed Apr 7, 2020
1 parent 5266d15 commit 96a7507
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ public static function removeContactBelongings($otherID, $tables) {
* @param bool $tables
* @param array $tableOperations
* @param array $customTableToCopyFrom
*
* @throws \CiviCRM_API3_Exception
*/
public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = [], $customTableToCopyFrom = NULL) {
$cidRefs = self::cidRefs();
Expand Down Expand Up @@ -558,15 +560,13 @@ public static function moveContactBelongings($mainId, $otherId, $tables = FALSE,
// run this INSERT for ContactReference fields
$sqls[] = "INSERT INTO $table ($field) VALUES ($mainId)";
}
$sqls[] = "UPDATE IGNORE $table SET $field = $mainId WHERE $field = $otherId";
$sqls[] = "DELETE FROM $table WHERE $field = $otherId";
$sqls[] = "UPDATE $table SET $field = $mainId WHERE $field = $otherId";
}
}

if (isset($eidRefs[$table])) {
foreach ($eidRefs[$table] as $entityTable => $entityId) {
$sqls[] = "UPDATE IGNORE $table SET $entityId = $mainId WHERE $entityId = $otherId AND $entityTable = 'civicrm_contact'";
$sqls[] = "DELETE FROM $table WHERE $entityId = $otherId AND $entityTable = 'civicrm_contact'";
$sqls[] = "UPDATE $table SET $entityId = $mainId WHERE $entityId = $otherId AND $entityTable = 'civicrm_contact'";
}
}
}
Expand Down

0 comments on commit 96a7507

Please sign in to comment.