From de1c25e19d74282fe41ed965cf70b61c540112ce Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Fri, 22 Mar 2013 17:41:12 +0530 Subject: [PATCH] --fixed for CRM-12155 --- CRM/Contribute/BAO/Contribution.php | 4 ++-- CRM/Core/BAO/FinancialTrxn.php | 30 ++++++++++------------------- CRM/Price/BAO/LineItem.php | 21 ++------------------ 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 7435436307..664c381154 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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'); diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index 75a266cae4..95a675df66 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -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; } /** diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index d33e2eaa13..89723470f1 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -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; } -- 2.25.1