CRM-12273 minor QA for some DB state observed after upgrade after checking PR 323
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 9 Apr 2013 16:25:46 +0000 (21:55 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 9 Apr 2013 16:25:46 +0000 (21:55 +0530)
CRM/Upgrade/Incremental/php/FourTwo.php

index 943c3ba20d16682e060c92b1354fc23b44288ffc..6630ac122cebaaa74f735084cb9302cf37565d54 100644 (file)
@@ -443,6 +443,11 @@ WHERE     cpse.price_set_id IS NULL";
       if (empty($optionValue))
         return;
     }
+    elseif (!CRM_Utils_Array::value('otherAmount', $options) && !CRM_Utils_Array::value('membership', $options)) {
+      //CRM-12273
+      //if options group, otherAmount, membersip is empty then return, contribution should be default price set
+      return;
+    }
 
     if (! CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_BAO_Set', $pageTitle, 'id', 'name', true)) {
       $setParams['name'] = $pageTitle;
@@ -629,8 +634,23 @@ WHERE     cpf.price_set_id = %1
       }
       else {
         $sql .= "AND cpfv.amount = %2";
+
+        //CRM-12273
+        //check if price_set_id is exist, if not use the default contribution amount
+        if (isset($result->price_set_id)){
+          $priceSetId = $result->price_set_id;
+        }
+        else{
+          $defaultPriceSets = CRM_Price_BAO_Set::getDefaultPriceSet();
+          foreach ($defaultPriceSets as $key => $pSet) {
+            if ($pSet['name'] == 'contribution_amount'){
+              $priceSetId = $pSet['setID'];
+            }
+          }
+        }
+
         $params = array(
-          '1' => array($result->price_set_id, 'Integer'),
+          '1' => array($priceSetId, 'Integer'),
           '2' => array($result->total_amount, 'String'),
         );
         $res = CRM_Core_DAO::executeQuery($sql, $params);
@@ -647,7 +667,7 @@ WHERE     cpf.price_set_id = %1
         }
         else {
           $params = array(
-            'price_set_id' => $result->price_set_id,
+            'price_set_id' => $priceSetId,
             'name' => 'other_amount',
           );
           $defaults = array();
@@ -660,7 +680,7 @@ WHERE     cpf.price_set_id = %1
           }
           else {
             $lineParams['price_field_id'] =
-              CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field', $result->price_set_id, 'id', 'price_set_id');
+              CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field', $priceSetId, 'id', 'price_set_id');
             $lineParams['label'] = 'Contribution Amount';
           }
           $lineParams['qty'] = 1;