From 595f9e7cfb113ec09fb3f177464c3afd3df23c9b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 2 Jun 2015 22:46:48 +1200 Subject: [PATCH] refactor pending one step closer to the form when renewing membership status - goal is to get it completely out of the form layer --- CRM/Batch/Form/Entry.php | 10 +++- CRM/Member/BAO/Membership.php | 54 +++++++++++++------ CRM/Member/Form/MembershipRenewal.php | 3 +- .../phpunit/CRM/Member/BAO/MembershipTest.php | 19 ++++++- 4 files changed, 66 insertions(+), 20 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 2b80fc9018..601a62d2bd 100755 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -786,8 +786,14 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper( $value['contact_id'], $value['membership_type_id'], - FALSE, $this, NULL, NULL, - $value['custom'] + FALSE, + $this, + NULL, + NULL, + $value['custom'], + 1, + NULL, + FALSE ); // make contribution entry diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 3313801ba5..62cda04ac0 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1520,19 +1520,24 @@ AND civicrm_membership.is_test = %2"; * @param int $membershipID * Membership ID, this should always be passed in & optionality should be removed. * - * @throws CRM_Core_Exception + * @param bool $isPending + * Is the transaction pending. We are working towards this ALWAYS being true and completion being done + * in the complete transaction function, called by all types of payment processor (removing assumptions + * about what they do & always doing a pending + a complete at the appropriate time). * + * @return */ public static function renewMembershipFormWrapper( $contactID, $membershipTypeID, $is_test, &$form, - $changeToday = NULL, - $modifiedID = NULL, - $customFieldsFormatted = NULL, - $numRenewTerms = 1, - $membershipID = NULL + $changeToday, + $modifiedID, + $customFieldsFormatted, + $numRenewTerms, + $membershipID, + $isPending ) { $statusFormat = '%Y-%m-%d'; $format = '%Y%m%d'; @@ -1548,8 +1553,10 @@ AND civicrm_membership.is_test = %2"; $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID); // check is it pending. - CRM-4555 - list($pending, $contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId) = self::extractFormValues($form, $changeToday, $membershipTypeDetails); - list($membership, $renewalMode, $dates) = self::renewMembership($contactID, $membershipTypeID, $is_test, $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $allStatus, $membershipTypeDetails, $contributionRecurID, $format, $membershipSource, $ids, $statusFormat, $isPayLater, $campaignId); + list($contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId) = self::extractFormValues($form, $changeToday); + list($membership, $renewalMode, $dates) = self::renewMembership($contactID, $membershipTypeID, $is_test, + $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $isPending, $allStatus, + $membershipTypeDetails, $contributionRecurID, $format, $membershipSource, $ids, $statusFormat, $isPayLater, $campaignId); $form->set('renewal_mode', $renewalMode); if (!empty($dates)) { $form->assign('mem_start_date', @@ -2303,7 +2310,8 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND $isTest, $form, NULL, CRM_Utils_Array::value('cms_contactID', $membershipParams), $customFieldsFormatted, $numTerms, - $membershipID + $membershipID, + self::extractPendingFormValue($form, $memType) ); if (!empty($membershipContribution)) { @@ -2332,15 +2340,19 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND } /** - * Extract relevant values from the form so we can separate form logic from BAO logcis. + * Determine if the form has a pending status. + * + * This is an interim refactoring step. This information should be extracted at the form layer. + * + * @deprecated * * @param CRM_Core_Form $form - * @param $changeToday - * @param $membershipTypeDetails + * @param int $membershipID * - * @return array + * @return bool */ - public static function extractFormValues($form, $changeToday, $membershipTypeDetails) { + public static function extractPendingFormValue($form, $membershipID) { + $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipID); $pending = FALSE; //@todo this is a BAO function & should not inspect the form - the form should do this // & pass required params to the BAO @@ -2354,6 +2366,18 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND $pending = TRUE; } } + return $pending; + } + + /** + * Extract relevant values from the form so we can separate form logic from BAO logcis. + * + * @param CRM_Core_Form $form + * @param $changeToday + * + * @return array + */ + public static function extractFormValues($form, $changeToday) { $contributionRecurID = isset($form->_params['contributionRecurID']) ? $form->_params['contributionRecurID'] : NULL; //we renew expired membership, CRM-6277 @@ -2384,7 +2408,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values); } } - return array($pending, $contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId); + return array($contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId); } /** diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index eb977eac39..77af3103d9 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -613,7 +613,8 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $formValues['membership_type_id'][1], $isTestMembership, $this, NULL, NULL, $customFieldsFormatted, $numRenewTerms, - $this->_membershipId + $this->_membershipId, + CRM_Member_BAO_Membership::extractPendingFormValue($this, $formValues['membership_type_id'][1]) ); $endDate = CRM_Utils_Date::processDate($renewMembership->end_date); diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index 94dc6854d1..2b2ba6c61a 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -528,7 +528,11 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $isTestMembership, $membershipRenewal, NULL, - NULL + NULL, + NULL, + 1, + NULL, + FALSE ); $endDate = date("Y-m-d", strtotime($membership->end_date . " +1 year")); @@ -602,7 +606,18 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $membershipRenewal = new CRM_Core_Form(); $membershipRenewal->controller = new CRM_Core_Controller(); - $MembershipRenew = CRM_Member_BAO_Membership::renewMembershipFormWrapper($contactId, $this->_membershipTypeID, $isTestMembership = 0, $membershipRenewal, NULL, NULL); + $MembershipRenew = CRM_Member_BAO_Membership::renewMembershipFormWrapper( + $contactId, + $this->_membershipTypeID, + $isTestMembership = 0, + $membershipRenewal, + NULL, + NULL, + NULL, + 1, + NULL, + FALSE + ); $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $MembershipRenew->id, -- 2.25.1