Skip to content

Commit

Permalink
Merge pull request #17336 from seamuslee001/fatal_exception_status_bo…
Browse files Browse the repository at this point in the history
…unce

dev/core#560 Replace some instances of CRM_Core_Error::fatal with an …
  • Loading branch information
eileenmcnaughton authored May 17, 2020
2 parents 79da31c + b583454 commit 22bafe4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 30 deletions.
5 changes: 3 additions & 2 deletions CRM/Case/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ public function creatNewShortcut(&$shortCuts) {
* 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 (
Expand All @@ -238,8 +240,7 @@ public static function onToggleComponents($oldValue, $newValue, $metadata) {
$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"));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Page/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function preProcess() {
}
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.');
}
}

Expand Down
27 changes: 9 additions & 18 deletions CRM/Case/XMLProcessor/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -56,10 +54,9 @@ public function get($caseType, $fieldSet, $isLabel = FALSE, $maskAction = FALSE)
$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) {
Expand Down Expand Up @@ -93,8 +90,7 @@ public function process($xml, &$params) {
$params
)
) {
CRM_Core_Error::fatal();
return FALSE;
throw new CRM_Core_Exception('Unable to create case relationships');
}
}
}
Expand Down Expand Up @@ -198,10 +194,9 @@ public function createRelationships($relationshipTypeXML, &$params) {
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'];
Expand All @@ -228,8 +223,7 @@ public function createRelationships($relationshipTypeXML, &$params) {
}

if (!$this->createRelationship($relationshipParams)) {
CRM_Core_Error::fatal();
return FALSE;
throw new CRM_Core_Exception('Unable to create case relationship');
}
}
return TRUE;
Expand Down Expand Up @@ -415,10 +409,9 @@ public function createActivity($activityTypeXML, &$params) {

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'];
Expand Down Expand Up @@ -549,8 +542,7 @@ public function createActivity($activityTypeXML, &$params) {
$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
Expand Down Expand Up @@ -740,8 +732,7 @@ public function getMaxInstance($caseType, $activityTypeName = NULL) {
$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);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function get($name, $attribute = NULL) {
* @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) {
Expand All @@ -87,7 +87,7 @@ public static function &getComponents($force = FALSE) {
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);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/DAO/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions CRM/Core/Invoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function hackMenuRebuild($args) {
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');
}
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public static function runItem($item) {

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
Expand Down Expand Up @@ -307,7 +307,7 @@ public static function runItem($item) {
$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);
}
Expand Down
6 changes: 4 additions & 2 deletions CRM/Core/Permission/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ public function checkGroupRole($array) {
* @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");
}

/**
Expand All @@ -181,9 +182,10 @@ public function permissionEmails($permissionName) {
* @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");
}

/**
Expand Down

0 comments on commit 22bafe4

Please sign in to comment.