// 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');
* @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;
}
/**
* @access public
* @static
*/
- public static function deleteLineItems($entityId, $entityTable) {
+ public static function deleteLineItems($entityId, $entityTable) {
if (!$entityId || !$entityTable) {
return FALSE;
}
$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;
}