From f1e48e7f41ccc00617ec4235ec69abb93ee99ba9 Mon Sep 17 00:00:00 2001 From: atif-shaikh Date: Thu, 23 Apr 2015 13:37:08 +0530 Subject: [PATCH] CRM-16300 fixed regression which caused webtest to break ---------------------------------------- * CRM-16300: Inherited membership is deleted when relationship is updated https://issues.civicrm.org/jira/browse/CRM-16300 --- CRM/Contact/BAO/Relationship.php | 13 +++++++++++-- CRM/Member/BAO/Membership.php | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 6330759c83..31e4e2108e 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1455,12 +1455,19 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) $memParams = array('contact_id' => $cid); $memberships = array(); - CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active); + CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active, TRUE); if (empty($memberships)) { continue; } + //get ownerMembershipIds for related Membership + //this is to handle memberships being deleted and recreated + if (!empty($memberships['owner_membership_ids'])) { + $ownerMemIds[$cid]= $memberships['owner_membership_ids']; + unset($memberships['owner_membership_ids']); + } + $values[$cid]['memberships'] = $memberships; } $deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus()); @@ -1558,9 +1565,11 @@ SELECT relationship_type_id, relationship_direction if ($action & CRM_Core_Action::UPDATE) { //if updated relationship is already related to contact don't delete existing inherited membership if (in_array($relTypeId, $relTypeIds - ) && !empty($values[$relatedContactId]['memberships'][$membershipValues['owner_membership_id']])) { + ) && !empty($values[$relatedContactId]['memberships']) && !empty($ownerMemIds + ) && in_array($membershipValues['owner_membership_id'], $ownerMemIds[$relatedContactId])) { continue; } + //delete the membership record for related //contact before creating new membership record. CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 497dadcd19..63c0abb012 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -194,10 +194,10 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { * @param bool $active * Do you want only active memberships to. * be returned - * + * @param bool $relatedMemberships * @return CRM_Member_BAO_Membership|null the found object or null */ - public static function &getValues(&$params, &$values, $active = FALSE) { + public static function &getValues(&$params, &$values, $active = FALSE, $relatedMemberships = FALSE) { if (empty($params)) { return NULL; } @@ -218,6 +218,9 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { CRM_Core_DAO::storeValues($membership, $values[$membership->id]); $memberships[$membership->id] = $membership; + if ($relatedMemberships && !empty($membership->owner_membership_id)) { + $values['owner_membership_ids'][] = $membership->owner_membership_id; + } } return $memberships; -- 2.25.1