Skip to content

Commit

Permalink
[#13] ignore relationships with contacts in trash
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Feb 24, 2023
1 parent bf8edf5 commit d510d79
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions CRM/Householdmerge/Logic/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,22 @@ protected function findCandidates($count) {

// try joining valid, active household relationships...
$RELATIONSHIP_JOIN = "
LEFT JOIN civicrm_relationship relation_ab ON contact_id = relation_ab.contact_id_a AND relation_ab.relationship_type_id IN ($relationship_id_list) AND (relation_ab.end_date IS NULL OR relation_ab.end_date > NOW()) AND relation_ab.is_active = 1
LEFT JOIN civicrm_contact relation_ab_contact ON relation_ab_contact.id = relation_ab.contact_id_b
LEFT JOIN civicrm_relationship relation_ba ON contact_id = relation_ba.contact_id_b AND relation_ba.relationship_type_id IN ($relationship_id_list) AND (relation_ba.end_date IS NULL OR relation_ba.end_date > NOW()) AND relation_ba.is_active = 1
LEFT JOIN civicrm_contact relation_ba_contact ON relation_ba_contact.id = relation_ba.contact_id_a
LEFT JOIN civicrm_relationship relation_ab ON contact_id = relation_ab.contact_id_a
AND relation_ab.relationship_type_id IN ($relationship_id_list)
AND (relation_ab.end_date IS NULL OR relation_ab.end_date > NOW())
AND relation_ab.is_active = 1
AND (relation_ab.contact_id_a IN (SELECT id FROM civicrm_contact WHERE is_deleted = 0))
LEFT JOIN civicrm_relationship relation_ba ON contact_id = relation_ba.contact_id_b
AND relation_ba.relationship_type_id IN ($relationship_id_list)
AND (relation_ba.end_date IS NULL OR relation_ba.end_date > NOW())
AND relation_ba.is_active = 1
AND (relation_ba.contact_id_a IN (SELECT id FROM civicrm_contact WHERE is_deleted = 0))
";

// ...and then make sure there are none
$RELATIONSHIP_CONDITION = "
AND (relation_ab_contact.is_deleted IS NULL OR relation_ab_contact.is_deleted = 0) -- NO RELATIONSHIP WITH DELETED CONTACT A EXISTS
AND (relation_ba_contact.is_deleted IS NULL OR relation_ba_contact.is_deleted = 0) -- NO RELATIONSHIP WITH DELETED CONTACT B EXISTS";
AND relation_ab.id IS NULL AND relation_ba.id IS NULL -- NO ACTIVE HH RELATIONSHIP EXISTS
";
}

$candidates = [];
Expand Down

0 comments on commit d510d79

Please sign in to comment.