From: Eileen McNaughton Date: Tue, 20 May 2014 00:38:49 +0000 (+1200) Subject: refactor creation of membership_payment records into shared function X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0547ad7ddd3defa985ea50e54e7d538b565c29fd;p=civicrm-core.git refactor creation of membership_payment records into shared function --- diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index e51d28800e..ae90d9aa14 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1321,17 +1321,7 @@ AND civicrm_membership.is_test = %2"; $createdMemberships[$memType] = $membership; if (!empty($membershipContribution)) { - //insert payment record - $dao = new CRM_Member_DAO_MembershipPayment(); - $dao->membership_id = $membership->id; - $dao->contribution_id = $membershipContribution->id; - //Fixed for avoiding duplicate entry error when user goes - //back and forward during payment mode is notify - if (!$dao->find(TRUE)) { - CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao); - $dao->save(); - CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao); - } + self::linkMembershipPayment($membership, $membershipContribution); } } if ($form->_priceSetId && !empty($form->_useForMember) && !empty($form->_lineItem)) { @@ -1362,17 +1352,7 @@ AND civicrm_membership.is_test = %2"; self::updateRecurMembership($membership, $membershipContribution); if (!empty($membershipContributionID)) { - //insert payment record - $dao = new CRM_Member_DAO_MembershipPayment(); - $dao->membership_id = $membership->id; - $dao->contribution_id = $membershipContributionID; - //Fixed for avoiding duplicate entry error when user goes - //back and forward during payment mode is notify - if (!$dao->find(TRUE)) { - CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao); - $dao->save(); - CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao); - } + self::linkMembershipPayment($membership, $membershipContribution); } } } @@ -2464,6 +2444,25 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND } } + /** + * 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) { + $dao = new CRM_Member_DAO_MembershipPayment(); + $dao->membership_id = $membership->id; + $dao->contribution_id = $membershipContribution->id; + //Fixed for avoiding duplicate entry error when user goes + //back and forward during payment mode is notify + if (!$dao->find(TRUE)) { + CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao); + $dao->save(); + CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao); + } + } + /** * Function to process price set and line items. *