From 5c19e6ace2da23c79da2cf6183bab4076f54ad50 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Wed, 12 Dec 2018 17:38:50 -0500 Subject: [PATCH] CiviMember: be more forgiving when `expired` status is disabled or missing --- CRM/Member/BAO/Membership.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 897226518b..d16175821c 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2241,7 +2241,7 @@ 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_PseudoConstant::membershipStatus(); + $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get'); $allTypes = CRM_Member_PseudoConstant::membershipType(); // This query retrieves ALL memberships of active types. @@ -2262,7 +2262,7 @@ FROM civicrm_membership INNER JOIN civicrm_contact ON ( civicrm_membership.contact_id = civicrm_contact.id ) INNER JOIN civicrm_membership_type ON (civicrm_membership.membership_type_id = civicrm_membership_type.id AND civicrm_membership_type.is_active = 1) -WHERE civicrm_membership.is_test = 0 +WHERE civicrm_membership.is_test = 0 AND civicrm_contact.is_deceased = 0 "; $deceaseStatusId = array_search('Deceased', $allStatus); @@ -2272,7 +2272,8 @@ WHERE civicrm_membership.is_test = 0 'Cancelled', CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE) ); - $expiredStatusId = array_search('Expired', $allStatus); + // Expired is not reserved so might not exist. A value of `0` won't break. + $expiredStatusId = array_search('Expired', $allStatus) ?: 0; $query = $baseQuery . " AND civicrm_membership.is_override IS NOT NULL AND civicrm_membership.status_override_end_date IS NOT NULL"; $dao1 = CRM_Core_DAO::executeQuery($query); -- 2.25.1