CRM-19587, code cleanup and fixes
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 1 Nov 2016 12:20:54 +0000 (17:50 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Wed, 2 Nov 2016 08:09:52 +0000 (13:39 +0530)
----------------------------------------
* CRM-19587: DB Error when trying to delete FInancial Account
  https://issues.civicrm.org/jira/browse/CRM-19587

CRM/Financial/BAO/FinancialAccount.php
CRM/Financial/Form/FinancialAccount.php

index 03902b4da8170002558bfbd53b0fe1ccf1dbe9e9..e1db8915aa8cf8417a72f696063259aea3eb5113 100644 (file)
@@ -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;
   }
 
   /**
index 7e7ce26dd3be9e149d173498b1d994c0a8e8ecf6..c43c1d8bcb99f7ca702b2ff742a3f15c461b876b 100644 (file)
@@ -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