From: Matthew Wire (MJW Consulting) Date: Fri, 23 Aug 2019 17:37:24 +0000 (+0100) Subject: Minor refactor of 'Pending' parameter for processMembership X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5b9d3ce80f1a64b39bdd63160ad0a1b960f2faed;p=civicrm-core.git Minor refactor of 'Pending' parameter for processMembership --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 25deceea7b..95fddb2ce9 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1364,7 +1364,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $membershipTypeIDs = (array) $membershipParams['selectMembership']; $membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIDs); $membershipType = empty($membershipTypes) ? [] : reset($membershipTypes); - $isPending = $this->getIsPending(); $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipType)); $this->_values['membership_name'] = CRM_Utils_Array::value('name', $membershipType); @@ -1392,7 +1391,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $this->postProcessMembership($membershipParams, $contactID, $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $financialTypeID, - $membershipLineItems, $isPending); + $membershipLineItems); $this->assign('membership_assign', TRUE); $this->set('membershipTypeID', $membershipParams['selectMembership']); @@ -1424,14 +1423,15 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr * @param int $financialTypeID * @param array $unprocessedLineItems * Line items for payment options chosen on the form. - * @param bool $isPending * * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + * @throws \Civi\Payment\Exception\PaymentProcessorException */ protected function postProcessMembership( $membershipParams, $contactID, &$form, $premiumParams, $customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeIDs, $isPaidMembership, $membershipID, - $isProcessSeparateMembershipTransaction, $financialTypeID, $unprocessedLineItems, $isPending) { + $isProcessSeparateMembershipTransaction, $financialTypeID, $unprocessedLineItems) { $membershipContribution = NULL; $isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE); @@ -1532,13 +1532,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } $i++; $numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1); - if (!empty($membershipContribution)) { - $pendingStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); - $pending = ($membershipContribution->contribution_status_id == $pendingStatus) ? TRUE : FALSE; - } - else { - $pending = $isPending; - } $contributionRecurID = isset($form->_params['contributionRecurID']) ? $form->_params['contributionRecurID'] : NULL; $membershipSource = NULL; @@ -1560,6 +1553,13 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } } + // @todo Move this into CRM_Member_BAO_Membership::processMembership + if (!empty($membershipContribution)) { + $pending = ($membershipContribution->contribution_status_id == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) ? TRUE : FALSE; + } + else { + $pending = $this->getIsPending(); + } list($membership, $renewalMode, $dates) = CRM_Member_BAO_Membership::processMembership( $contactID, $memType, $isTest, date('YmdHis'), CRM_Utils_Array::value('cms_contactID', $membershipParams), diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 4c984618d3..fe2849ec5c 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -585,12 +585,12 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $membershipSource = $this->_params['membership_source']; } - $isPending = ($this->_params['contribution_status_id'] == 2) ? TRUE : FALSE; - + // @todo Move this into CRM_Member_BAO_Membership::processMembership + $pending = ($this->_params['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) ? TRUE : FALSE; list($membership) = CRM_Member_BAO_Membership::processMembership( $this->_contactID, $this->_params['membership_type_id'][1], $isTestMembership, $renewalDate, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId, - $isPending, + $pending, $contributionRecurID, $membershipSource, $this->_params['is_pay_later'], CRM_Utils_Array::value('campaign_id', $this->_params) );