From b5834543b8bed747b73c20de80dddd284ad1a386 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 16 May 2020 10:12:53 +1000 Subject: [PATCH] dev/core#560 Replace some instances of CRM_Core_Error::fatal with an exception or status bounce --- CRM/Case/Info.php | 5 +++-- CRM/Case/Page/Tab.php | 2 +- CRM/Case/XMLProcessor/Process.php | 27 +++++++++------------------ CRM/Core/Component.php | 4 ++-- CRM/Core/DAO/Factory.php | 4 ++-- CRM/Core/Invoke.php | 6 +++--- CRM/Core/Permission/Base.php | 6 ++++-- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/CRM/Case/Info.php b/CRM/Case/Info.php index 0f996ee0c8..bf9d4adca5 100644 --- a/CRM/Case/Info.php +++ b/CRM/Case/Info.php @@ -228,6 +228,8 @@ class CRM_Case_Info extends CRM_Core_Component_Info { * List of component names. * @param array $metadata * Specification of the setting (per *.settings.php). + * + * @throws \CRM_Core_Exception. */ public static function onToggleComponents($oldValue, $newValue, $metadata) { if ( @@ -238,8 +240,7 @@ class CRM_Case_Info extends CRM_Core_Component_Info { $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; self::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl'); if (!CRM_Case_BAO_Case::createCaseViews()) { - $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); - CRM_Core_Error::fatal($msg); + throw new CRM_Core_Exception(ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission")); } } } diff --git a/CRM/Case/Page/Tab.php b/CRM/Case/Page/Tab.php index e89132c3de..12f6cd0671 100644 --- a/CRM/Case/Page/Tab.php +++ b/CRM/Case/Page/Tab.php @@ -63,7 +63,7 @@ class CRM_Case_Page_Tab extends CRM_Core_Page { } else { if ($this->_action & CRM_Core_Action::VIEW) { - CRM_Core_Error::fatal('Contact Id is required for view action.'); + CRM_Core_Error::statusBounce('Contact Id is required for view action.'); } } diff --git a/CRM/Case/XMLProcessor/Process.php b/CRM/Case/XMLProcessor/Process.php index 4eb4e8826e..2385eaf200 100644 --- a/CRM/Case/XMLProcessor/Process.php +++ b/CRM/Case/XMLProcessor/Process.php @@ -23,18 +23,16 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor { * @param string $caseType * @param array $params * - * @return bool - * @throws Exception + * @throws CRM_Core_Exception */ public function run($caseType, &$params) { $xml = $this->retrieve($caseType); if ($xml === FALSE) { $docLink = CRM_Utils_System::docURL2("user/case-management/set-up"); - CRM_Core_Error::fatal(ts("Configuration file could not be retrieved for case type = '%1' %2.", + throw new CRM_Core_Exception(ts("Configuration file could not be retrieved for case type = '%1' %2.", [1 => $caseType, 2 => $docLink] )); - return FALSE; } $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); @@ -56,10 +54,9 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor { $xml = $this->retrieve($caseType); if ($xml === FALSE) { $docLink = CRM_Utils_System::docURL2("user/case-management/set-up"); - CRM_Core_Error::fatal(ts("Unable to load configuration file for the referenced case type: '%1' %2.", + throw new CRM_Core_Exception(ts("Unable to load configuration file for the referenced case type: '%1' %2.", [1 => $caseType, 2 => $docLink] )); - return FALSE; } switch ($fieldSet) { @@ -93,8 +90,7 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor { $params ) ) { - CRM_Core_Error::fatal(); - return FALSE; + throw new CRM_Core_Exception('Unable to create case relationships'); } } } @@ -198,10 +194,9 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor { list($relationshipType, $relationshipTypeName) = $this->locateNameOrLabel($relationshipTypeXML); if ($relationshipType === FALSE) { $docLink = CRM_Utils_System::docURL2("user/case-management/set-up"); - CRM_Core_Error::fatal(ts('Relationship type %1, found in case configuration file, is not present in the database %2', + throw new CRM_Core_Exception(ts('Relationship type %1, found in case configuration file, is not present in the database %2', [1 => $relationshipTypeName, 2 => $docLink] )); - return FALSE; } $client = $params['clientID']; @@ -228,8 +223,7 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor { } if (!$this->createRelationship($relationshipParams)) { - CRM_Core_Error::fatal(); - return FALSE; + throw new CRM_Core_Exception('Unable to create case relationship'); } } return TRUE; @@ -415,10 +409,9 @@ AND a.is_deleted = 0 if (!$activityTypeInfo) { $docLink = CRM_Utils_System::docURL2("user/case-management/set-up"); - CRM_Core_Error::fatal(ts('Activity type %1, found in case configuration file, is not present in the database %2', + throw new CRM_Core_Exception(ts('Activity type %1, found in case configuration file, is not present in the database %2', [1 => $activityTypeName, 2 => $docLink] )); - return FALSE; } $activityTypeID = $activityTypeInfo['id']; @@ -549,8 +542,7 @@ AND a.is_deleted = 0 $activity = CRM_Activity_BAO_Activity::create($activityParams); if (!$activity) { - CRM_Core_Error::fatal(); - return FALSE; + throw new CRM_Core_Exception('Unable to create Activity'); } // create case activity record @@ -740,8 +732,7 @@ AND a.is_deleted = 0 $xml = $this->retrieve($caseType); if ($xml === FALSE) { - CRM_Core_Error::fatal(); - return FALSE; + throw new CRM_Core_Exception('Unable to read supplied XML File'); } $activityInstances = $this->activityTypes($xml->ActivityTypes, TRUE); diff --git a/CRM/Core/Component.php b/CRM/Core/Component.php index b96694a43d..c594c3b6d8 100644 --- a/CRM/Core/Component.php +++ b/CRM/Core/Component.php @@ -70,7 +70,7 @@ class CRM_Core_Component { * @param bool $force * * @return CRM_Core_Component_Info[] - * @throws Exception + * @throws CRM_Core_Exception */ public static function &getComponents($force = FALSE) { if (!isset(Civi::$statics[__CLASS__]['all']) || $force) { @@ -87,7 +87,7 @@ class CRM_Core_Component { require_once $infoClassFile; $infoObject = new $infoClass($cr->name, $cr->namespace, $cr->id); if ($infoObject->info['name'] !== $cr->name) { - CRM_Core_Error::fatal("There is a discrepancy between name in component registry and in info file ({$cr->name})."); + throw new CRM_Core_Exception("There is a discrepancy between name in component registry and in info file ({$cr->name})."); } Civi::$statics[__CLASS__]['all'][$cr->name] = $infoObject; unset($infoObject); diff --git a/CRM/Core/DAO/Factory.php b/CRM/Core/DAO/Factory.php index 66dd5a9d74..1401d2ba1d 100644 --- a/CRM/Core/DAO/Factory.php +++ b/CRM/Core/DAO/Factory.php @@ -24,12 +24,12 @@ class CRM_Core_DAO_Factory { * @param string $className * * @return mixed - * @throws Exception + * @throws CRM_Core_Exception */ public static function create($className) { $type = self::$_classes[$className] ?? NULL; if (!$type) { - CRM_Core_Error::fatal("class $className not found"); + throw new CRM_Core_Exception("class $className not found"); } $class = self::$_prefix[$type] . $className; diff --git a/CRM/Core/Invoke.php b/CRM/Core/Invoke.php index b0262dfda7..780ae182fa 100644 --- a/CRM/Core/Invoke.php +++ b/CRM/Core/Invoke.php @@ -102,7 +102,7 @@ class CRM_Core_Invoke { return CRM_Utils_System::redirect(); } else { - CRM_Core_Error::fatal('You do not have permission to execute this url'); + CRM_Core_Error::statusBounce('You do not have permission to execute this url'); } } } @@ -224,7 +224,7 @@ class CRM_Core_Invoke { if (!array_key_exists('page_callback', $item)) { CRM_Core_Error::debug('Bad item', $item); - CRM_Core_Error::fatal(ts('Bad menu record in database')); + CRM_Core_Error::statusBounce(ts('Bad menu record in database')); } // check that we are permissioned to access this page @@ -307,7 +307,7 @@ class CRM_Core_Invoke { $object = new $item['page_callback']($title, TRUE, $mode, NULL, $addSequence); } else { - CRM_Core_Error::fatal(); + throw new CRM_Core_Exception('Execute supplied menu action'); } $result = $object->run($newArgs, $pageArgs); } diff --git a/CRM/Core/Permission/Base.php b/CRM/Core/Permission/Base.php index a91c126b8c..b3f5a066f1 100644 --- a/CRM/Core/Permission/Base.php +++ b/CRM/Core/Permission/Base.php @@ -170,9 +170,10 @@ class CRM_Core_Permission_Base { * @param string $permissionName * Name of the permission we are interested in. * + * @throws CRM_Core_Exception. */ public function permissionEmails($permissionName) { - CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); + throw new CRM_Core_Exception("this function only works in Drupal 6 at the moment"); } /** @@ -181,9 +182,10 @@ class CRM_Core_Permission_Base { * @param string $roleName * Name of the role we are interested in. * + * @throws CRM_Core_Exception. */ public function roleEmails($roleName) { - CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); + throw new CRM_Core_Exception("this function only works in Drupal 6 at the moment"); } /** -- 2.25.1