-- CRM-15475, Retrieved value for membership status id regardless of civicrm_membersh...
authorPradeep Nayak <pradpnayak@gmail.com>
Mon, 3 Nov 2014 05:26:54 +0000 (10:56 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 3 Nov 2014 06:02:32 +0000 (11:32 +0530)
----------------------------------------
* 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
CRM/Member/Form/Membership.php
CRM/Member/PseudoConstant.php

index 5b513ef5677d9d40e145c9b179c08047d5dbbaee..d1f405cb760ab9e0b7d9210ae1224bb6699da893 100644 (file)
@@ -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'),
     );
 
index 51b7d5e3bac6d2b83376e4fe2c28598fe4dfea71..90dbcc742fd75a66225f19896fbf29f2c6da11c2 100644 (file)
@@ -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;
index 434923bac1f3b992b33713aac3db8d86a7129ebb..fbcdaa9a00d4bb29ac2fb165cb1bca8bb2680598 100644 (file)
@@ -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'
       );
     }