From afe1f7cb9e5dac581b8e5fed48b4009d12a4bdd6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 15 Apr 2021 06:51:47 +1200 Subject: [PATCH] Revert "dev/core#2512 Set membership's status properly when recording the payment" --- CRM/Contribute/BAO/Contribution.php | 21 ++++-------- .../Contribute/Form/AdditionalPaymentTest.php | 32 ------------------- 2 files changed, 7 insertions(+), 46 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index fd5fbb8f43..7e030b8f38 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4771,8 +4771,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac 'membership_activity_status' => 'Completed', ]; - $currentMembership = []; - CRM_Member_BAO_Membership::retrieve($membershipParams, $currentMembership); + $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'], + $membershipParams['membership_type_id'], + $membershipParams['is_test'], + $membershipParams['id'] + ); // CRM-8141 update the membership type with the value recorded in log when membership created/renewed // this picks up membership type changes during renewals @@ -4790,8 +4793,7 @@ LIMIT 1;"; $membershipParams['membership_type_id'] = $dao->membership_type_id; } } - $pendingMembershipStatusID = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending'); - if (empty($membership['end_date']) || (int) $membership['status_id'] !== $pendingMembershipStatusID) { + if (empty($membership['end_date']) || (int) $membership['status_id'] !== CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending')) { // Passing num_terms to the api triggers date calculations, but for pending memberships these may be already calculated. // sigh - they should be consistent but removing the end date check causes test failures & maybe UI too? // The api assumes num_terms is a special sauce for 'is_renewal' so we need to not pass it when updating a pending to completed. @@ -4809,16 +4811,7 @@ LIMIT 1;"; 'start_date', 'end_date', ], NULL); - if ($currentMembership && (int) $currentMembership['status_id'] === $pendingMembershipStatusID) { - $currentMembership['join_date'] = $currentMembership['join_date'] ?? NULL; - $currentMembership['start_date'] = $currentMembership['start_date'] ?? NULL; - $currentMembership['end_date'] = $currentMembership['end_date'] ?? NULL; - - $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipParams['membership_type_id'], - $currentMembership['join_date'], $currentMembership['start_date'], $currentMembership['end_date'] - ); - } - else { + if ($currentMembership) { /* * Fixed FOR CRM-4433 * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status diff --git a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php index 6925b110f4..229317008a 100644 --- a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php @@ -313,38 +313,6 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->validateAllPayments(); } - /** - * Test the Membership status renaming after completing the pending pay later Contribution. - * - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception - */ - public function testMembershipStatusAfterCompletingPayLaterContributionWithRenamedMembershipStatus() { - $this->renameNewMembershipStatus('Fresh'); - $this->createPendingOrder(); - $membership = $this->createPendingMembershipAndRecordContribution($this->_contributionId); - // pay additional amount - $this->submitPayment(100); - $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]); - $contributionMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership['id']]); - $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['id' => $contributionMembership['status_id']]); - $this->assertEquals('Fresh', $membershipStatus['name']); - $this->validateAllPayments(); - } - - /** - * @param $membershipStatusName - * - * @throws \CRM_Core_Exception - */ - private function renameNewMembershipStatus($membershipStatusName) { - $params = [ - 'name' => 'New', - 'api.MembershipStatus.create' => ['name' => $membershipStatusName], - ]; - $this->callAPISuccess('MembershipStatus', 'get', $params); - } - /** * @param $contributionId * -- 2.25.1