From e62adec92c94820985016821266ca50c873c02a0 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Wed, 26 Aug 2015 15:36:45 +0530 Subject: [PATCH] CRM-12078 -- change inherited membership status to expired instead of deleting them when relationship is updated --- CRM/Contact/BAO/Relationship.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index e0f036e707..1148e95bdc 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1647,19 +1647,22 @@ SELECT count(*) // if action is update and updated relationship do // not match with the existing // membership=>relationship then we need to - // delete the membership record created for - // previous relationship. - // CRM-16087 we need to pass ownerMembershipId to deleteRelatedMemberships function + // change the status of the membership record to expired for + // previous relationship -- CRM-12078. + // CRM-16087 we need to pass ownerMembershipId to isRelatedMembershipExpired function if (empty($params['relationship_ids']) && !empty($params['id'])) { $relIds = array($params['id']); } else { $relIds = CRM_Utils_Array::value('relationship_ids', $params); } - if (self::isDeleteRelatedMembership($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, + if (self::isRelatedMembershipExpired($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, $relIds) && !empty($membershipValues['owner_membership_id'] ) && !empty($values[$mainRelatedContactId]['memberships'][$membershipValues['owner_membership_id']])) { - CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']); + $membershipValues['status_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', 'Expired', 'id', 'label'); + $type = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $membershipValues['membership_type_id'], 'name', 'id'); + CRM_Member_BAO_Membership::add($membershipValues); + CRM_Core_Session::setStatus(ts("Inherited membership {$type} status was changed to Expired due to the change in relationship type."), ts('Record Updated'), 'alert'); } } } @@ -1667,10 +1670,10 @@ SELECT count(*) } /** - * Helper function to check whether to delete the membership or not. + * Helper function to check whether the membership is expired or not. * * Function takes a list of related membership types and if it is not also passed a - * relationship ID of that types evaluates whether the membership should be deleted. + * relationship ID of that types evaluates whether the membership status should be changed to expired. * * @param array $membershipTypeRelationshipTypeIDs * Relation type IDs related to the given membership type. @@ -1681,7 +1684,7 @@ SELECT count(*) * * @return bool */ - public static function isDeleteRelatedMembership($membershipTypeRelationshipTypeIDs, $contactId, $mainRelatedContactId, $relTypeId, $relIds) { + public static function isRelatedMembershipExpired($membershipTypeRelationshipTypeIDs, $contactId, $mainRelatedContactId, $relTypeId, $relIds) { if (empty($membershipTypeRelationshipTypeIDs) || in_array($relTypeId, $membershipTypeRelationshipTypeIDs)) { return FALSE; } -- 2.25.1