From: Eileen McNaughton Date: Fri, 11 Jul 2014 01:39:44 +0000 (+1200) Subject: CRM-14972 fix for test breakage - the fix part X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5624f515a906986b7dde71bc0cdf165d671ad00f;p=civicrm-core.git CRM-14972 fix for test breakage - the fix part --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index a560d3962d..c8cec31f30 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -958,17 +958,18 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } if (!empty($membershipParams['selectMembership'])) { // CRM-12233 + $membershipLineItems = array(); if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) { foreach ($this->_values['fee'] as $key => $feeValues) { - if ($feeValues['name'] == 'membership_amount') { + if ($feeValues['name'] == 'membership_amount') { $fieldId = $this->_params['price_' . $key]; - $this->_memLineItem[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId]; + $membershipLineItems[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId]; unset($this->_lineItem[$this->_priceSetId][$fieldId]); break; } } } - $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams); + $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems); 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 @@ -1691,18 +1692,22 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } /** - * @param $membershipParams - * @param $contactID - * @param $customFieldsFormatted - * @param $fieldTypes - * @param $premiumParams + * @param array $membershipParams + * @param integer $contactID + * @param array $customFieldsFormatted + * @param array $fieldTypes + * @param array $premiumParams + * @param array $membershipLineItems line items specifically relating to memberships */ - public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams) { + public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems) { try { $membershipTypeID = (array) $membershipParams['selectMembership']; - $membershipDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this); - $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipDetails)); + $membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this); + + $membershipType = empty($membershipTypes) ? array() : reset($membershipTypes); + $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipType)); + $isPaidMembership = FALSE; if($this->_amount > 0.0 && $membershipParams['amount']) { //amount must be greater than zero for @@ -1717,14 +1722,12 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $contributionTypeId = $this->_values['financial_type_id']; } else { - $contributionTypeId = CRM_Utils_Array::value( 'financial_type_id', $membershipDetails ); - if (!$contributionTypeId) { - $contributionTypeId = CRM_Utils_Array::value('financial_type_id' ,$membershipParams); - } + $contributionTypeId = CRM_Utils_Array::value('financial_type_id', $membershipType, CRM_Utils_Array::value('financial_type_id' ,$membershipParams)); } CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID, - $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipDetails, $membershipTypeID, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId + $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeID, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId, + $membershipLineItems ); $this->assign('membership_assign', TRUE); $this->set('membershipTypeID', $membershipParams['selectMembership']); @@ -1838,6 +1841,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $priceFields = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID); $priceSetFields = reset($priceFields); $form->_values['fee'] = $priceSetFields['fields']; + $form->_priceSetId = $priceSetID; $form->setFormAmountFields($priceSetID); $priceFields = $priceFields[$priceSetID]['fields']; CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution'); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 88d20b8eb2..ed09f8b4d5 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -976,14 +976,14 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty else { $dao->whereAdd('is_test IS NULL OR is_test = 0'); } - + //avoid pending membership as current membership: CRM-3027 $statusIds[] = array_search('Pending', CRM_Member_PseudoConstant::membershipStatus()); if (!$membershipId) { $statusIds[] = array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus()); } $dao->whereAdd('status_id NOT IN ( ' . implode(',', $statusIds) . ')'); - + // order by start date to find most recent membership first, CRM-4545 $dao->orderBy('start_date DESC'); @@ -1239,7 +1239,7 @@ AND civicrm_membership.is_test = %2"; * * @param array $membershipParams array of membership fields * @param int $contactID contact id - * @param object $form form object + * @param CRM_Contribute_Form_Contribution_Confirm $form Confirmation form object * * @param $premiumParams * @param null $customFieldsFormatted @@ -1255,18 +1255,15 @@ AND civicrm_membership.is_test = %2"; * @param $isProcessSeparateMembershipTransaction * * @param $defaultContributionTypeID - * + * @param array $membershipLineItems Line items specific to membership payment that is separate to contribution * @throws CRM_Core_Exception - * @internal param \isProcessSeparateMembershipTransaction $bool $ - * - * @internal param $singleMembershipTypeID * * @return void * @access public */ public static function postProcessMembership($membershipParams, $contactID, &$form, $premiumParams, $customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeID, $isPaidMembership, $membershipID, - $isProcessSeparateMembershipTransaction, $defaultContributionTypeID) { + $isProcessSeparateMembershipTransaction, $defaultContributionTypeID, $membershipLineItems) { $result = NULL; $isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE); $errors = $createdMemberships = array(); @@ -1291,7 +1288,8 @@ AND civicrm_membership.is_test = %2"; if ($isProcessSeparateMembershipTransaction) { try { - $membershipContribution = self::processSecondaryFinancialTransaction($contactID, $form, $membershipDetails, $membershipParams, $isTest); + $lineItems = $form->_lineItem = $membershipLineItems; + $membershipContribution = self::processSecondaryFinancialTransaction($contactID, $form, $membershipParams, $isTest, $membershipLineItems, CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0), CRM_Utils_Array::value('financial_type_id', $membershipDetails)); } catch (CRM_Core_Exception $e) { $errors[2] = $e->getMessage(); @@ -2089,21 +2087,17 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND * Where a second separate financial transaction is supported we will process it here * * @param $contactID - * @param $form + * @param CRM_Contribute_Form_Contribution_Confirm $form * @param $membershipDetails * @param $tempParams - * @param $errors * @param $isTest * - * @throws Exception - * @internal param $minimumFee + * @throws CRM_Core_Exception * @return CRM_Contribute_BAO_Contribution */ - public static function processSecondaryFinancialTransaction($contactID, &$form, $membershipDetails, $tempParams, $isTest) { - $minimumFee = CRM_Utils_Array::value('minimum_fee', $membershipDetails); - $lineItems = $form->_lineItem = $form->_memLineItem; + public static function processSecondaryFinancialTransaction($contactID, &$form, $tempParams, $isTest, $lineItems, $minimumFee, $financialTypeID) { $contributionType = new CRM_Financial_DAO_FinancialType(); - $contributionType->id = CRM_Utils_Array::value('financial_type_id', $membershipDetails); + $contributionType->id = $financialTypeID; if (!$contributionType->find(TRUE)) { CRM_Core_Error::fatal(ts("Could not find a system table")); } @@ -2143,11 +2137,11 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND // irrespective of the value, CRM-2888 $tempParams['cms_create_account'] = 0; - $pending = $form->_params['is_pay_later'] ? ((CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0) > 0.0) ? TRUE : FALSE) : FALSE; + $pending = $form->_params['is_pay_later'] ? (($minimumFee > 0.0) ? TRUE : FALSE) : FALSE; //set this variable as we are not creating pledge for //separate membership payment contribution. - //so for differentiating membership contributon from + //so for differentiating membership contribution from //main contribution. $form->_params['separate_membership_payment'] = 1; $membershipContribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($form, @@ -2916,12 +2910,12 @@ WHERE civicrm_membership.is_test = 0"; self::$_renewalActType = CRM_Utils_Array::key('Membership Renewal', $activityTypes); self::$_signupActType = CRM_Utils_Array::key('Membership Signup', $activityTypes); } - + /** * Get all Cancelled Membership(s) for a contact * * @param int $contactID contact id - * @param boolean $isTest mode of payment + * @param boolean $isTest mode of payment * * @return array of membership type * @static @@ -2930,7 +2924,7 @@ WHERE civicrm_membership.is_test = 0"; static function getContactsCancelledMembership($contactID, $isTest = FALSE) { if (!$contactID) { return array(); - } + } $allStatus = CRM_Member_PseudoConstant::membershipStatus(); $query = 'SELECT membership_type_id FROM civicrm_membership WHERE contact_id = %1 AND status_id = %2 AND is_test = %3'; $queryParams = array( @@ -2938,7 +2932,7 @@ WHERE civicrm_membership.is_test = 0"; 2 => array(array_search('Cancelled', $allStatus), 'Integer'), 3 => array($isTest, 'Boolean'), ); - + $dao = CRM_Core_DAO::executeQuery($query, $queryParams); $cancelledMembershipIds = array(); while ($dao->fetch()) {