--fixed for CRM-12155
authorPradeep Nayak <pradeep@pradeep.(none)>
Fri, 22 Mar 2013 12:11:12 +0000 (17:41 +0530)
committerPradeep Nayak <pradeep@pradeep.(none)>
Fri, 22 Mar 2013 12:11:12 +0000 (17:41 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Core/BAO/FinancialTrxn.php
CRM/Price/BAO/LineItem.php

index 7435436307be45fb63a4ec7db0587ec0821a9aea..664c381154c441263387b01c01d8677f7b274204 100644 (file)
@@ -700,8 +700,8 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = civicrm_contribution.conta
     // cleanup line items.
     $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
 
-    // delete any related entity_financial_trxn and financial_trxn records.
-    CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution');
+    // delete any related entity_financial_trxn, financial_trxn and financial_item records.
+    CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id);
 
     if ($participantId) {
       CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
index 75a266cae440941e092eb5c72c759752ae552581..95a675df667c3d8ec978141dc9b58abcebdcacb5 100644 (file)
@@ -260,26 +260,16 @@ WHERE lt.entity_id = %1 ";
    * @static
    */
   static function deleteFinancialTrxn($entity_id) {
-    $fids = self::getFinancialTrxnId($entity_id);
-
-    if ($fids['financialTrxnId']) {
-      // delete enity financial transaction before financial transaction since financial_trxn_id will be set to null if financial transaction deleted first
-      $query = 'DELETE FROM civicrm_entity_financial_trxn  WHERE financial_trxn_id = %1';
-      CRM_Core_DAO::executeQuery($query, array(1 => array($fids['financialTrxnId'], 'Integer')));
-
-      // delete financial transaction
-      $query = 'DELETE FROM civicrm_financial_trxn WHERE id = %1';
-      CRM_Core_DAO::executeQuery($query, array(1 => array($fids['financialTrxnId'], 'Integer')));
-
-      // delete financial item record
-      $query = 'DELETE FROM civicrm_financial_item WHERE entity_table="civicrm_financial_trxn" AND entity_id = %1';
-      CRM_Core_DAO::executeQuery($query, array(1 => array($fids['financialTrxnId'], 'Integer')));
-
-      return TRUE;
-    }
-    else {
-      return FALSE;
-    }
+    $query = "DELETE ceft1, cfi, ceft, cft FROM `civicrm_financial_trxn` cft
+LEFT JOIN civicrm_entity_financial_trxn ceft 
+  ON ceft.financial_trxn_id = cft.id AND ceft.entity_table = 'civicrm_contribution'
+LEFT JOIN civicrm_entity_financial_trxn ceft1
+  ON ceft1.financial_trxn_id = cft.id AND ceft1.entity_table = 'civicrm_financial_item'
+LEFT JOIN civicrm_financial_item cfi 
+  ON ceft1.entity_table = 'civicrm_financial_item' and cfi.id = ceft1.entity_id
+WHERE ceft.entity_id = %1";
+    CRM_Core_DAO::executeQuery($query, array(1 => array($entity_id, 'Integer')));
+    return TRUE;
   }
 
   /**
index d33e2eaa1339791dbc602b2d40b5efe9ff2d0ebb..89723470f15cea356e81ce56f81a3cde239454c8 100644 (file)
@@ -241,7 +241,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem {
    * @access public
    * @static
    */
-  public static function deleteLineItems($entityId, $entityTable) {
+  public static function deleteLineItems($entityId, $entityTable) { 
     if (!$entityId || !$entityTable) {
       return FALSE;
     }
@@ -250,25 +250,8 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem {
       $entityId = array($entityId);
     }
 
-    // we need to fetch the line item ids that needs to be deleted.
-    $query = "SELECT id FROM civicrm_line_item WHERE entity_id IN ('" . implode("','", $entityId) . "') AND entity_table = '$entityTable'";
+    $query = "DELETE FROM civicrm_line_item where entity_id IN ('" . implode("','", $entityId) . "') AND entity_table = '$entityTable'";
     $dao = CRM_Core_DAO::executeQuery($query);
-
-    $lineItemIds = array();
-    while($dao->fetch()) {
-      $lineItemIds[$dao->id] = $dao->id;
-    }
-
-    // delete line item records from financial item
-    if (!empty($lineItemIds)) {
-      $query = "DELETE FROM civicrm_financial_item WHERE entity_id IN ('" . implode("','", $lineItemIds) . "') AND entity_table = 'civicrm_line_item'";
-      CRM_Core_DAO::executeQuery($query);
-    }
-
-    // delete records from line item
-    $query = "DELETE FROM civicrm_line_item WHERE entity_id IN ('" . implode("','", $entityId) . "') AND entity_table = '$entityTable'";
-    CRM_Core_DAO::executeQuery($query);
-
     return TRUE;
   }