From 15c3308bbf82ba16fba8fc8cd7558288e362354a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 20 May 2014 13:13:49 +1200 Subject: [PATCH] share create membership function & move compiling errors into a separate function --- CRM/Member/BAO/Membership.php | 44 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index f6fe962114..22e1fc58fb 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1330,33 +1330,19 @@ AND civicrm_membership.is_test = %2"; } } else { - $membership = $createdMemberships[$membershipTypeID] = self::renewMembership($contactID, $membershipTypeID, - $isTest, $form, NULL, - CRM_Utils_Array::value('cms_contactID', $membershipParams), - $customFieldsFormatted, CRM_Utils_Array::value('types_terms', $membershipParams, 1) - ); - - // update recurring id for membership record - self::updateRecurMembership($membership, $membershipContribution); - - if (!empty($membershipContributionID)) { - self::linkMembershipPayment($membership, $membershipContribution); - } + $numTerms = CRM_Utils_Array::value('types_terms', $membershipParams, 1); + $createdMemberships[$membershipTypeID] = self::createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $membershipTypeID, $isTest, $numTerms, $membershipContribution, $createdMemberships); } } if (!empty($errors)) { - foreach ($errors as $error) { - if (is_string($error)) { - $message[] = $error; - } - } - $message = ts('Payment Processor Error message') . ': ' . implode('
', $message); + $message = self::compileErrorMessage($errors); throw new CRM_Core_Exception($message); } $form->_params['createdMembershipIDs'] = array(); // CRM-7851 - Moved after processing Payment Errors + //@todo - the reasoning for this being here seems a little outdated foreach ($createdMemberships as $createdMembership) { CRM_Core_BAO_CustomValueTable::postProcess( $form->_params, @@ -2466,8 +2452,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND * * @return array */ - public static function createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $memType, $isTest, $numTerms, $membershipContribution, &$form) - { + public static function createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $memType, $isTest, $numTerms, $membershipContribution, &$form) { $membership = self::renewMembership($contactID, $memType, $isTest, $form, NULL, CRM_Utils_Array::value('cms_contactID', $membershipParams), @@ -2484,6 +2469,25 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND return $membership; } + /** + * Turn array of errors into message string + * + * @param array $errors + * + * @internal param $message + * + * @return string + */ + public static function compileErrorMessage($errors) + { + foreach($errors as $error) { + if (is_string($error)) { + $message[] = $error; + } + } + return ts('Payment Processor Error message') . ': ' . implode('
', $message); + } + /** * Function to process price set and line items. * -- 2.25.1