Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/dev/core#2152: Merge contacts keep case roles #18884

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -1896,14 +1896,15 @@ public static function getPermissionedContacts($contactID, $relTypeId = NULL, $n
public static function mergeRelationships($mainId, $otherId, &$sqls) {
// Delete circular relationships
$sqls[] = "DELETE FROM civicrm_relationship
WHERE (contact_id_a = $mainId AND contact_id_b = $otherId)
OR (contact_id_b = $mainId AND contact_id_a = $otherId)";
WHERE (contact_id_a = $mainId AND contact_id_b = $otherId AND case_id IS NULL)
OR (contact_id_b = $mainId AND contact_id_a = $otherId AND case_id IS NULL)";

// Delete relationship from other contact if main contact already has that relationship
$sqls[] = "DELETE r2
FROM civicrm_relationship r1, civicrm_relationship r2
WHERE r1.relationship_type_id = r2.relationship_type_id
AND r1.id <> r2.id
AND r1.case_id IS NULL AND r2.case_id IS NULL
AND (
r1.contact_id_a = $mainId AND r2.contact_id_a = $otherId AND r1.contact_id_b = r2.contact_id_b
OR r1.contact_id_b = $mainId AND r2.contact_id_b = $otherId AND r1.contact_id_a = r2.contact_id_a
Expand Down