From 4cf017d11c4fa0d896e245e0307607c774258233 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 7 Jun 2020 17:24:03 +1200 Subject: [PATCH] [Ref] Remove some instances of fatal in BAO classes --- CRM/Batch/BAO/Batch.php | 8 +++----- CRM/Campaign/BAO/Petition.php | 5 ++--- CRM/Cxn/CiviCxnHttp.php | 2 +- CRM/Financial/BAO/PaymentProcessor.php | 4 ++-- CRM/Financial/BAO/PaymentProcessorType.php | 2 +- CRM/Member/BAO/Membership.php | 2 +- CRM/Utils/HttpClient.php | 3 --- 7 files changed, 10 insertions(+), 16 deletions(-) diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index f44c0e4999..3bb93f140b 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -579,12 +579,10 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { */ public static function exportFinancialBatch($batchIds, $exportFormat, $downloadFile) { if (empty($batchIds)) { - CRM_Core_Error::fatal(ts('No batches were selected.')); - return; + throw new CRM_Core_Exception(ts('No batches were selected.')); } if (empty($exportFormat)) { - CRM_Core_Error::fatal(ts('No export format selected.')); - return; + throw new CRM_Core_Exception(ts('No export format selected.')); } self::$_exportFormat = $exportFormat; @@ -594,7 +592,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { $exporter = new $exporterClass(); } else { - CRM_Core_Error::fatal("Could not locate exporter: $exporterClass"); + throw new CRM_Core_Exception("Could not locate exporter: $exporterClass"); } $export = []; $exporter->_isDownloadFile = $downloadFile; diff --git a/CRM/Campaign/BAO/Petition.php b/CRM/Campaign/BAO/Petition.php index 406b38f70f..72e2151a64 100644 --- a/CRM/Campaign/BAO/Petition.php +++ b/CRM/Campaign/BAO/Petition.php @@ -266,8 +266,7 @@ AND tag_id = ( SELECT id FROM civicrm_tag WHERE name = %2 )"; return TRUE; } else { - CRM_Core_Error::fatal(ts('Petition Id and/or Activity Id is not of the type Positive.')); - return FALSE; + throw new CRM_Core_Exception(ts('Petition Id and/or Activity Id is not of the type Positive.')); } } @@ -561,7 +560,7 @@ AND tag_id = ( SELECT id FROM civicrm_tag WHERE name = %2 )"; $petitionInfo = []; CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo); if (empty($petitionInfo)) { - CRM_Core_Error::fatal('Petition doesn\'t exist.'); + throw new CRM_Core_Exception('Petition doesn\'t exist.'); } //get the default domain email address. diff --git a/CRM/Cxn/CiviCxnHttp.php b/CRM/Cxn/CiviCxnHttp.php index a972c7fd35..17aa4fb549 100644 --- a/CRM/Cxn/CiviCxnHttp.php +++ b/CRM/Cxn/CiviCxnHttp.php @@ -107,7 +107,7 @@ class CRM_Cxn_CiviCxnHttp extends \Civi\Cxn\Rpc\Http\PhpHttp { $result['ssl'] = $caConfig->toStreamOptions(); } if (!$caConfig->isEnableSSL() && preg_match('/^https:/', $url)) { - CRM_Core_Error::fatal('Cannot fetch document - system does not support SSL'); + throw new CRM_Core_Exception('Cannot fetch document - system does not support SSL'); } return $result; diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index 363828f31a..ed37743c5a 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -49,7 +49,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces $ppTypeDAO = new CRM_Financial_DAO_PaymentProcessorType(); $ppTypeDAO->id = $params['payment_processor_type_id']; if (!$ppTypeDAO->find(TRUE)) { - CRM_Core_Error::fatal(ts('Could not find payment processor meta information')); + throw new CRM_Core_Exception(ts('Could not find payment processor meta information')); } // also copy meta fields from the info DAO @@ -194,7 +194,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces */ public static function del($paymentProcessorID) { if (!$paymentProcessorID) { - CRM_Core_Error::fatal(ts('Invalid value passed to delete function.')); + throw new CRM_Core_Exception(ts('Invalid value passed to delete function.')); } $dao = new CRM_Financial_DAO_PaymentProcessor(); diff --git a/CRM/Financial/BAO/PaymentProcessorType.php b/CRM/Financial/BAO/PaymentProcessorType.php index e64fb29713..c0f49c2b10 100644 --- a/CRM/Financial/BAO/PaymentProcessorType.php +++ b/CRM/Financial/BAO/PaymentProcessorType.php @@ -141,7 +141,7 @@ class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentPr $ppByName = self::getAllPaymentProcessorTypes('name'); if (array_key_exists($paymentProcessorType->name, $ppByName)) { if ($ppByName[$paymentProcessorType->name] != $paymentProcessorType->id) { - CRM_Core_Error::fatal('This payment processor type already exists.'); + throw new CRM_Core_Exception('This payment processor type already exists.'); } } } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index df5e17a48d..03961d953e 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1062,7 +1062,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND */ public static function getMembershipCount($membershipTypeId, $date = NULL, $isTest = 0, $isOwner = 0) { if (!CRM_Utils_Rule::date($date)) { - CRM_Core_Error::fatal(ts('Invalid date "%1" (must have form yyyy-mm-dd).', [1 => $date])); + throw new CRM_Core_Exception(ts('Invalid date "%1" (must have form yyyy-mm-dd).', [1 => $date])); } $params = [ diff --git a/CRM/Utils/HttpClient.php b/CRM/Utils/HttpClient.php index c7989ec626..c2d12ae18c 100644 --- a/CRM/Utils/HttpClient.php +++ b/CRM/Utils/HttpClient.php @@ -117,7 +117,6 @@ class CRM_Utils_HttpClient { list($ch, $caConfig) = $this->createCurl($remoteFile); if (preg_match('/^https:/', $remoteFile) && !$caConfig->isEnableSSL()) { - // CRM_Core_Error::fatal('Cannot install this extension - does not support SSL'); return [self::STATUS_DL_ERROR, NULL]; } @@ -146,14 +145,12 @@ class CRM_Utils_HttpClient { public function post($remoteFile, $params) { // Download extension zip file ... if (!function_exists('curl_init')) { - //CRM_Core_Error::fatal('Cannot install this extension - curl is not installed!'); return [self::STATUS_DL_ERROR, NULL]; } list($ch, $caConfig) = $this->createCurl($remoteFile); if (preg_match('/^https:/', $remoteFile) && !$caConfig->isEnableSSL()) { - // CRM_Core_Error::fatal('Cannot install this extension - does not support SSL'); return [self::STATUS_DL_ERROR, NULL]; } -- 2.25.1