From 4e60e3752d8fee1c64ddf81c17bf057975c54753 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Mon, 18 Mar 2019 12:03:38 -0400 Subject: [PATCH] CiviMember: excluding Expired memberships by name, not label --- CRM/Member/BAO/Membership.php | 12 ++++++------ .../phpunit/CRM/Member/BAO/MembershipStatusTest.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index d16175821c..bce4b15e54 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2241,7 +2241,11 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND // Tests for this function are in api_v3_JobTest. Please add tests for all updates. $updateCount = $processCount = self::updateDeceasedMembersStatuses(); - $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get'); + + // We want all of the statuses as id => name, even the disabled ones (cf. + // CRM-15475), to identify which are Pending, Deceased, Cancelled, and + // Expired. + $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'validate'); $allTypes = CRM_Member_PseudoConstant::membershipType(); // This query retrieves ALL memberships of active types. @@ -2267,11 +2271,7 @@ WHERE civicrm_membership.is_test = 0 $deceaseStatusId = array_search('Deceased', $allStatus); $pendingStatusId = array_search('Pending', $allStatus); - // CRM-15475 - $cancelledStatusId = array_search( - 'Cancelled', - CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE) - ); + $cancelledStatusId = array_search('Cancelled', $allStatus); // Expired is not reserved so might not exist. A value of `0` won't break. $expiredStatusId = array_search('Expired', $allStatus) ?: 0; diff --git a/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php b/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php index 5128a5ccfe..fa118e1373 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipStatusTest.php @@ -132,7 +132,7 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { public function testExpiredDisabled() { $result = civicrm_api3('MembershipStatus', 'get', [ - 'label' => "Expired", + 'name' => "Expired", 'api.MembershipStatus.create' => ['is_active' => 0], ]); @@ -140,7 +140,7 @@ class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase { $result = $this->callAPISuccess('job', 'process_membership', []); $result = civicrm_api3('MembershipStatus', 'get', [ - 'label' => "Expired", + 'name' => "Expired", 'api.MembershipStatus.delete' => [], ]); -- 2.25.1