From fd88af0bff698952c9f9dde2b8572f47a6786776 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 15 Jun 2018 08:42:42 +0100 Subject: [PATCH] Cleanup of api_v3_membership_create towards #11556 --- api/v3/Membership.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/api/v3/Membership.php b/api/v3/Membership.php index 4f0c657a91..34af5cd09d 100644 --- a/api/v3/Membership.php +++ b/api/v3/Membership.php @@ -101,9 +101,12 @@ function civicrm_api3_membership_create($params) { _civicrm_api3_custom_format_params($params, $values, 'Membership'); $params = array_merge($params, $values); + // Calculate membership dates // Fixme: This code belongs in the BAO if (empty($params['id']) || !empty($params['num_terms'])) { + // If this is a new membership or we have a specified number of terms calculate membership dates. if (empty($params['id'])) { + // This is a new membership, calculate the membership dates. $calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType( $params['membership_type_id'], CRM_Utils_Array::value('join_date', $params), @@ -113,6 +116,7 @@ function civicrm_api3_membership_create($params) { ); } else { + // This is an existing membership, calculate the membership dates after renewal $calcDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType( $params['id'], NULL, @@ -128,20 +132,20 @@ function civicrm_api3_membership_create($params) { } // Fixme: This code belongs in the BAO - $action = CRM_Core_Action::ADD; - // we need user id during add mode - $ids = array(); - if (!empty($params['contact_id'])) { - $ids['userId'] = $params['contact_id']; + if (empty($params['id'])) { + $params['action'] = CRM_Core_Action::ADD; + // we need user id during add mode + $ids = array(); + if (!empty($params['contact_id'])) { + $ids['userId'] = $params['contact_id']; + } } - //for edit membership id should be present - // probably not required now. - if (!empty($params['id'])) { + else { + // edit mode + $params['action'] = CRM_Core_Action::UPDATE; + // $ids['membership'] is required in CRM_Price_BAO_LineItem::processPriceSet $ids['membership'] = $params['id']; - $action = CRM_Core_Action::UPDATE; } - //need to pass action to handle related memberships. - $params['action'] = $action; $membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE); -- 2.25.1