Skip to content

Commit

Permalink
Merge pull request #22516 from eileenmcnaughton/legacy2
Browse files Browse the repository at this point in the history
Merge function back into parent function
  • Loading branch information
eileenmcnaughton authored Jan 16, 2022
2 parents 2d5dd21 + 2eb14f6 commit 83634f6
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions CRM/Contact/BAO/Contact/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,33 @@ public static function createCurrentEmployerRelationship($contactID, $employerID
// set current employer
self::setCurrentEmployer([$contactID => $employerID]);

$relationshipParams = [
'relationship_ids' => $relationshipIds,
'is_active' => 1,
'contact_check' => [$employerID => TRUE],
'relationship_type_id' => $relationshipTypeID . '_a_b',
];
// Handle related memberships. CRM-3792
self::currentEmployerRelatedMembership($contactID, $employerID, $relationshipParams, $duplicate, $previousEmployerID);
$ids = [];
$action = CRM_Core_Action::ADD;

//we do not know that triggered relationship record is active.
if ($duplicate) {
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->contact_id_a = $contactID;
$relationship->contact_id_b = $employerID;
$relationship->relationship_type_id = $relationshipTypeID;
if ($relationship->find(TRUE)) {
$action = CRM_Core_Action::UPDATE;
$ids['contact'] = $contactID;
$ids['contactTarget'] = $employerID;
$ids['relationship'] = $relationship->id;
CRM_Contact_BAO_Relationship::setIsActive($relationship->id, TRUE);
}
}

//need to handle related memberships. CRM-3792
if ($previousEmployerID != $employerID) {
CRM_Contact_BAO_Relationship::relatedMemberships($contactID, [
'relationship_ids' => $relationshipIds,
'is_active' => 1,
'contact_check' => [$employerID => TRUE],
'relationship_type_id' => $relationshipTypeID . '_a_b',
], $ids, $action);
}
}

/**
Expand Down Expand Up @@ -380,28 +399,7 @@ private static function legacyCreateMultiple(int $relationshipTypeID, int $organ
* @throws \CRM_Core_Exception
*/
private static function currentEmployerRelatedMembership($contactID, $employerID, $relationshipParams, $duplicate = FALSE, $previousEmployerID = NULL) {
$ids = [];
$action = CRM_Core_Action::ADD;

//we do not know that triggered relationship record is active.
if ($duplicate) {
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->contact_id_a = $contactID;
$relationship->contact_id_b = $employerID;
$relationship->relationship_type_id = $relationshipParams['relationship_type_id'];
if ($relationship->find(TRUE)) {
$action = CRM_Core_Action::UPDATE;
$ids['contact'] = $contactID;
$ids['contactTarget'] = $employerID;
$ids['relationship'] = $relationship->id;
CRM_Contact_BAO_Relationship::setIsActive($relationship->id, TRUE);
}
}

//need to handle related memberships. CRM-3792
if ($previousEmployerID != $employerID) {
CRM_Contact_BAO_Relationship::relatedMemberships($contactID, $relationshipParams, $ids, $action);
}
}

/**
Expand Down

0 comments on commit 83634f6

Please sign in to comment.