From c9cc6e3a9bffa3d850af24bbbdc276faead235aa Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Fri, 26 Jul 2019 16:30:47 +0100 Subject: [PATCH] Switch create MembershipPayment to use API --- CRM/Contribute/Form/Contribution/Confirm.php | 9 ++++++-- CRM/Member/BAO/Membership.php | 24 +++++--------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 236a98cccf..601b3bf3b4 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1578,8 +1578,13 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if (!empty($membershipContribution)) { // update recurring id for membership record CRM_Member_BAO_Membership::updateRecurMembership($membership, $membershipContribution); - // Next line is probably redundant. Checksprevent it happening twice. - CRM_Member_BAO_Membership::linkMembershipPayment($membership, $membershipContribution); + // Next line is probably redundant. Checks prevent it happening twice. + $membershipPaymentParams = [ + 'membership_id' => $membership->id, + 'membership_type_id' => $membership->membership_type_id, + 'contribution_id' => $membershipContribution->id, + ]; + civicrm_api3('MembershipPayment', 'create', $membershipPaymentParams); } if ($membership) { CRM_Core_BAO_CustomValueTable::postProcess($form->_params, 'civicrm_membership', $membership->id, 'Membership'); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 833b049fa2..e7d3adae81 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -397,11 +397,12 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { //insert payment record for this membership if (!empty($params['relate_contribution_id'])) { - CRM_Member_BAO_MembershipPayment::create(array( + $membershipPaymentParams = [ 'membership_id' => $membership->id, 'membership_type_id' => $membership->membership_type_id, 'contribution_id' => $params['relate_contribution_id'], - )); + ]; + civicrm_api3('MembershipPayment', 'create', $membershipPaymentParams); } $transaction->commit(); @@ -1802,20 +1803,6 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND return (int) $memberCount; } - /** - * Create linkages between membership & contribution - note this is the wrong place for this code but this is a - * refactoring step. This should be BAO functionality - * @param $membership - * @param $membershipContribution - */ - public static function linkMembershipPayment($membership, $membershipContribution) { - CRM_Member_BAO_MembershipPayment::create(array( - 'membership_id' => $membership->id, - 'membership_type_id' => $membership->membership_type_id, - 'contribution_id' => $membershipContribution->id, - )); - } - /** * @param int $contactID * @param int $membershipTypeID @@ -2507,11 +2494,12 @@ WHERE civicrm_membership.is_test = 0 //insert payment record for this membership if (empty($ids['contribution']) || !empty($params['is_recur'])) { - CRM_Member_BAO_MembershipPayment::create(array( + civicrm_api3('MembershipPayment', 'create', [ 'membership_id' => $membershipId, 'contribution_id' => $contribution->id, - )); + ]); } + return $contribution; } -- 2.25.1