From fa9d045151695dee87b9107d308b841d232c2761 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 21 May 2014 10:51:17 +1200 Subject: [PATCH] CRM-14197 membership post process refactor CMS usermove CMS create user back out of process membership & pass membership id to renewmembership --- CRM/Contribute/Form/Contribution/Confirm.php | 20 ++++++++- CRM/Member/BAO/Membership.php | 43 +++++++++----------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 42df5a419b..b0666ec6a4 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1009,8 +1009,15 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } } } - $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams); + if (!$this->_amount > 0.0 || !$membershipParams['amount']) { + // we need to explicitly create a CMS user in case of free memberships + // since it is done under processConfirm for paid memberships + CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams, + $membershipParams['cms_contactID'], + 'email-' . $this->_bltID + ); + } } } else { @@ -1741,8 +1748,17 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $membershipDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $singleMembershipTypeID); $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipDetails)); + $isPaidMembership = FALSE; + if($this->_amount > 0.0 && $membershipParams['amount']) { + //amount must be greater than zero for + //adding contribution record to contribution table. + //this condition arises when separate membership payment is + //enabled and contribution amount is not selected. fix for CRM-3010 + $isPaidMembership = TRUE; + } + CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID, - $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipDetails, $membershipTypeID + $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipDetails, $membershipTypeID, $isPaidMembership, $this->_membershipId ); $this->assign('membership_assign', TRUE); $this->set('membershipTypeID', $membershipParams['selectMembership']); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 29b31c0b3e..6155727d56 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1242,9 +1242,12 @@ AND civicrm_membership.is_test = %2"; * @param null $customFieldsFormatted * @param null $includeFieldTypes * - * @param $membershipDetails + * @param array $membershipDetails * - * @param $membershipTypeID + * @param array $membershipTypeID + * + * @param bool $isPaidMembership + * @param integer $membershipID * * @throws CRM_Core_Exception * @throws Exception @@ -1254,7 +1257,7 @@ AND civicrm_membership.is_test = %2"; * @access public */ public static function postProcessMembership($membershipParams, $contactID, &$form, $premiumParams, - $customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeID + $customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeID, $isPaidMembership, $membershipID ) { $tempParams = $membershipParams; $paymentDone = FALSE; @@ -1274,25 +1277,13 @@ AND civicrm_membership.is_test = %2"; } } - //amount must be greater than zero for - //adding contribution record to contribution table. - //this condition arises when separate membership payment is - //enabled and contribution amount is not selected. fix for CRM-3010 - if ($form->_amount > 0.0 && $membershipParams['amount']) { + if ($isPaidMembership) { $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams, $premiumParams, $contactID, $contributionTypeId, 'membership' ); } - else { - // we need to explicitly create a CMS user in case of free memberships - // since the below has already been done under processConfirm for paid memberships - CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams, - $membershipParams['cms_contactID'], - 'email-' . $form->_bltID - ); - } $errors = array(); if (is_a($result[1], 'CRM_Core_Error')) { @@ -1387,7 +1378,8 @@ AND civicrm_membership.is_test = %2"; $membership = self::renewMembership($contactID, $memType, $isTest, $form, NULL, CRM_Utils_Array::value('cms_contactID', $membershipParams), - $customFieldsFormatted, CRM_Utils_Array::value($memType, $typesTerms, 1) + $customFieldsFormatted, CRM_Utils_Array::value($memType, $typesTerms, 1), + $membershipID ); // update recurring id for membership record @@ -1548,12 +1540,14 @@ AND civicrm_membership.is_test = %2"; * @param null $customFieldsFormatted * @param int $numRenewTerms how many membership terms are being added to end date (default is 1) * + * @param integer $membershipID Membership ID, this should always be passed in & optionality should be removed + * + * @throws CRM_Core_Exception * @internal param array $ipnParams array of name value pairs, to be used (for e.g source) when $form not present * @return CRM_Member_DAO_Membership $membership object of membership * * @static * @access public - * */ static function renewMembership( $contactID, @@ -1563,11 +1557,16 @@ AND civicrm_membership.is_test = %2"; $changeToday = NULL, $modifiedID = NULL, $customFieldsFormatted = NULL, - $numRenewTerms = 1 + $numRenewTerms = 1, + $membershipID = NULL ) { $statusFormat = '%Y-%m-%d'; $format = '%Y%m%d'; $ids = array(); + //@todo would be better to make $membershipID a compulsory function param & make form layer responsible for extracting it + if(!$membershipID && isset($form->_membershipId)) { + $membershipID = $form->_membershipId; + } //get all active statuses of membership. $allStatus = CRM_Member_PseudoConstant::membershipStatus(); @@ -1593,11 +1592,7 @@ AND civicrm_membership.is_test = %2"; //decide status here, if needed. $updateStatusId = NULL; - $membershipID = NULL; - //@todo would be better to accept $membershipID as an FN param & make form layer responsible for extracting it - if(isset($form->_membershipId)) { - $membershipID = $form->_membershipId; - } + // CRM-7297 - allow membership type to be be changed during renewal so long as the parent org of new membershipType // is the same as the parent org of an existing membership of the contact $currentMembership = CRM_Member_BAO_Membership::getContactMembership($contactID, $membershipTypeID, -- 2.25.1