From 05b9ff02539850856c1349b3530fa5a359ef4fd3 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 1 Nov 2016 17:50:54 +0530 Subject: [PATCH] CRM-19587, code cleanup and fixes ---------------------------------------- * CRM-19587: DB Error when trying to delete FInancial Account https://issues.civicrm.org/jira/browse/CRM-19587 --- CRM/Financial/BAO/FinancialAccount.php | 3 ++- CRM/Financial/Form/FinancialAccount.php | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 03902b4da8..e1db8915aa 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -158,13 +158,14 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco if ($check) { CRM_Core_Session::setStatus(ts('This financial account cannot be deleted since it is being used as a header account. Please remove it from being a header account before trying to delete it again.')); - return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount', "reset=1&action=browse")); + return FALSE; } // delete from financial Type table $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->id = $financialAccountId; $financialAccount->delete(); + return TRUE; } /** diff --git a/CRM/Financial/Form/FinancialAccount.php b/CRM/Financial/Form/FinancialAccount.php index 7e7ce26dd3..c43c1d8bcb 100644 --- a/CRM/Financial/Form/FinancialAccount.php +++ b/CRM/Financial/Form/FinancialAccount.php @@ -202,8 +202,12 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { - CRM_Financial_BAO_FinancialAccount::del($this->_id); - CRM_Core_Session::setStatus(ts('Selected Financial Account has been deleted.')); + if (CRM_Financial_BAO_FinancialAccount::del($this->_id)) { + CRM_Core_Session::setStatus(ts('Selected Financial Account has been deleted.')); + } + else { + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount', "reset=1&action=browse")); + } } else { // store the submitted values in an array -- 2.25.1