From 7ff60806520b94fad653518d02d9bf0b5547081d Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Mon, 3 Nov 2014 10:56:54 +0530 Subject: [PATCH] -- CRM-15475, Retrieved value for membership status id regardless of civicrm_membership_status.is_active field ---------------------------------------- * CRM-15475: Fatal error on membership page if membership status 'Cancelled' is disabled https://issues.civicrm.org/jira/browse/CRM-15475 --- CRM/Member/BAO/Membership.php | 39 ++++++++++++++++++++++++++++------ CRM/Member/Form/Membership.php | 6 +++--- CRM/Member/PseudoConstant.php | 4 ++-- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 5b513ef567..d1f405cb76 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -988,7 +988,17 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty //avoid pending membership as current membership: CRM-3027 $statusIds[] = array_search('Pending', CRM_Member_PseudoConstant::membershipStatus()); if (!$membershipId) { - $statusIds[] = array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus()); + // CRM-15475 + $statusIds[] = array_search( + 'Cancelled', + CRM_Member_PseudoConstant::membershipStatus( + NULL, + " name = 'Cancelled' ", + 'name', + FALSE, + TRUE + ) + ); } $dao->whereAdd('status_id NOT IN ( ' . implode(',', $statusIds) . ')'); @@ -2004,7 +2014,7 @@ LEFT JOIN civicrm_membership mem ON ( cr.id = mem.contribution_recur_id ) WHERE mem.id = %1 LIMIT 1"; $params = array(1 => array($mid, 'Integer')); $statusId = CRM_Core_DAO::singleValueQuery($sql, $params); - $status = CRM_Contribute_PseudoConstant::contributionStatus($statusId); + $status = CRM_Contribute_PseudoConstant::contributionStatus($statusId, 'name'); if ($status == 'Cancelled') { return TRUE; } @@ -2347,7 +2357,8 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND //1. membership with status : PENDING/CANCELLED (CRM-2395) //2. Paylater/IPN renew. CRM-4556. if ($pending || in_array($currentMembership['status_id'], array(array_search('Pending', $allStatus), - array_search('Cancelled', $allStatus), + // CRM-15475 + array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)), )) ) { $membership = new CRM_Member_DAO_Membership(); @@ -2719,7 +2730,11 @@ WHERE civicrm_membership.is_test = 0"; //skipping Expired membership records -> reduced extra processing( kiran ) if (!$dao->is_override && !in_array($dao->status_id, array(array_search('Pending', $allStatus), - array_search('Cancelled', $allStatus), + // CRM-15475 + array_search( + 'Cancelled', + CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE) + ), array_search('Expired', $allStatus), )) ) { @@ -2957,11 +2972,23 @@ WHERE civicrm_membership.is_test = 0"; if (!$contactID) { return array(); } - $allStatus = CRM_Member_PseudoConstant::membershipStatus(); $query = 'SELECT membership_type_id FROM civicrm_membership WHERE contact_id = %1 AND status_id = %2 AND is_test = %3'; $queryParams = array( 1 => array($contactID, 'Integer'), - 2 => array(array_search('Cancelled', $allStatus), 'Integer'), + 2 => array( + // CRM-15475 + array_search( + 'Cancelled', + CRM_Member_PseudoConstant::membershipStatus( + NULL, + " name = 'Cancelled' ", + 'name', + FALSE, + TRUE + ) + ), + 'Integer' + ), 3 => array($isTest, 'Boolean'), ); diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 51b7d5e3ba..90dbcc742f 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1587,10 +1587,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //display end date w/ status message. $endDate = $membership->end_date; - $membershipStatues = CRM_Member_PseudoConstant::membershipStatus(); if (!in_array($membership->status_id, array( - array_search('Cancelled', $membershipStatues), - array_search('Expired', $membershipStatues), + // CRM-15475 + array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)), + array_search('Expired', CRM_Member_PseudoConstant::membershipStatus()), )) ) { $cancelled = FALSE; diff --git a/CRM/Member/PseudoConstant.php b/CRM/Member/PseudoConstant.php index 434923bac1..fbcdaa9a00 100644 --- a/CRM/Member/PseudoConstant.php +++ b/CRM/Member/PseudoConstant.php @@ -96,7 +96,7 @@ class CRM_Member_PseudoConstant extends CRM_Core_PseudoConstant { * @return array - array reference of all membership statuss if any * @static */ - public static function &membershipStatus($id = NULL, $cond = NULL, $column = 'name', $force = FALSE) { + public static function &membershipStatus($id = NULL, $cond = NULL, $column = 'name', $force = FALSE, $allStatus = FALSE) { if (self::$membershipStatus === NULL) { self::$membershipStatus = array(); } @@ -108,7 +108,7 @@ class CRM_Member_PseudoConstant extends CRM_Core_PseudoConstant { if (!isset(self::$membershipStatus[$cacheKey]) || $force) { CRM_Core_PseudoConstant::populate(self::$membershipStatus[$cacheKey], 'CRM_Member_DAO_MembershipStatus', - FALSE, $column, 'is_active', $cond, 'weight' + $allStatus, $column, 'is_active', $cond, 'weight' ); } -- 2.25.1