From 309310bf0df830e742126db7b3ba3e0dc0ea884c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 9 Nov 2019 07:31:57 +1100 Subject: [PATCH] Converts using deprated fatal function for exception in CRM/Utils/System and in CRM/Utils/Cache and changes default for retrieve function in the Request class to throw exceptions Update doc blocks --- CRM/Utils/Cache.php | 3 ++- CRM/Utils/Request.php | 2 +- CRM/Utils/System/Backdrop.php | 2 +- CRM/Utils/System/Base.php | 4 +++- CRM/Utils/System/Drupal.php | 2 +- CRM/Utils/System/Drupal6.php | 2 +- CRM/Utils/System/Joomla.php | 3 ++- CRM/Utils/System/WordPress.php | 8 +++++--- 8 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CRM/Utils/Cache.php b/CRM/Utils/Cache.php index 1fb4cce63c..8acfed5527 100644 --- a/CRM/Utils/Cache.php +++ b/CRM/Utils/Cache.php @@ -55,9 +55,10 @@ class CRM_Utils_Cache { * An array of configuration params. * * @return \CRM_Utils_Cache + * @throws \CRM_Core_Exception */ public function __construct(&$config) { - CRM_Core_Error::fatal(ts('this is just an interface and should not be called directly')); + throw new CRM_Core_Exception(ts('this is just an interface and should not be called directly')); } /** diff --git a/CRM/Utils/Request.php b/CRM/Utils/Request.php index 2bb8df3412..d3c7872924 100644 --- a/CRM/Utils/Request.php +++ b/CRM/Utils/Request.php @@ -87,7 +87,7 @@ class CRM_Utils_Request { * * @throws \CRM_Core_Exception */ - public static function retrieve($name, $type, &$store = NULL, $abort = FALSE, $default = NULL, $method = 'REQUEST', $isThrowException = FALSE) { + public static function retrieve($name, $type, &$store = NULL, $abort = FALSE, $default = NULL, $method = 'REQUEST', $isThrowException = TRUE) { $value = NULL; switch ($method) { diff --git a/CRM/Utils/System/Backdrop.php b/CRM/Utils/System/Backdrop.php index f139dda3dd..ab8bd72a97 100644 --- a/CRM/Utils/System/Backdrop.php +++ b/CRM/Utils/System/Backdrop.php @@ -309,7 +309,7 @@ class CRM_Utils_System_Backdrop extends CRM_Utils_System_DrupalBase { $dbBackdrop = DB::connect($config->userFrameworkDSN); if (DB::isError($dbBackdrop)) { - CRM_Core_Error::fatal("Cannot connect to Backdrop database via $config->userFrameworkDSN, " . $dbBackdrop->getMessage()); + throw new CRM_Core_Exception("Cannot connect to Backdrop database via $config->userFrameworkDSN, " . $dbBackdrop->getMessage()); } $account = $userUid = $userMail = NULL; diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 0dca55f657..8f16278794 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -152,6 +152,7 @@ abstract class CRM_Utils_System_Base { * * @return array|bool * [contactID, ufID, unique string] else false if no auth + * @throws \CRM_Core_Exception. */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { return FALSE; @@ -179,9 +180,10 @@ abstract class CRM_Utils_System_Base { /** * Immediately stop script execution and display a 401 "Access Denied" page. + * @throws \CRM_Core_Exception */ public function permissionDenied() { - CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); + throw new CRM_Core_Exception(ts('You do not have permission to access this page.')); } /** diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index e23a24d750..dc9ae60737 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -322,7 +322,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { $dbDrupal = DB::connect($config->userFrameworkDSN); if (DB::isError($dbDrupal)) { - CRM_Core_Error::fatal("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage()); + throw new CRM_Core_Exception("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage()); } $account = $userUid = $userMail = NULL; diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 5c49dce78d..9ffae34ec6 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -318,7 +318,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { $dbDrupal = DB::connect($config->userFrameworkDSN); if (DB::isError($dbDrupal)) { - CRM_Core_Error::fatal("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage()); + throw new CRM_Core_Exception("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage()); } $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index ce67ed26f5..956dd83670 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -473,9 +473,10 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * FIXME: Use CMS-native approach + * @throws \CRM_Core_Exception. */ public function permissionDenied() { - CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); + throw new CRM_Core_Exception(ts('You do not have permission to access this page.')); } /** diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 2b47fbb373..b79669fa37 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -388,9 +388,10 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { /** * FIXME: Use CMS-native approach + * @throws \CRM_Core_Exception */ public function permissionDenied() { - CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); + throw new CRM_Core_Exception(ts('You do not have permission to access this page.')); } /** @@ -463,6 +464,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { * @param mixed $realPath * * @return bool + * @throws \CRM_Core_Exception */ public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) { global $wp, $wp_rewrite, $wp_the_query, $wp_query, $wpdb, $current_site, $current_blog, $current_user; @@ -476,7 +478,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { $cmsRootPath = $this->cmsRootPath(); if (!$cmsRootPath) { - CRM_Core_Error::fatal("Could not find the install directory for WordPress"); + throw new CRM_Core_Exception("Could not find the install directory for WordPress"); } $path = Civi::settings()->get('wpLoadPhp'); if (!empty($path)) { @@ -486,7 +488,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { require_once $cmsRootPath . DIRECTORY_SEPARATOR . 'wp-load.php'; } else { - CRM_Core_Error::fatal("Could not find the bootstrap file for WordPress"); + throw new CRM_Core_Exception("Could not find the bootstrap file for WordPress"); } $wpUserTimezone = get_option('timezone_string'); if ($wpUserTimezone) { -- 2.25.1