Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Replace some instances of fatal with thrown exceptions. #17533

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRM/Bridge/OG/CiviCRM.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function group($groupID, $group, $op) {
* @param $group
*/
public static function groupAdd($groupID, $group) {
$ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE);
$ogID = CRM_Bridge_OG_Utils::ogID($groupID);

$node = new StdClass();
if ($ogID) {
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function groupAdd($groupID, $group) {
* @param $group
*/
public static function groupDelete($groupID, $group) {
$ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE);
$ogID = CRM_Bridge_OG_Utils::ogID($groupID);
if (!$ogID) {
return;
}
Expand All @@ -84,7 +84,7 @@ public static function groupDelete($groupID, $group) {
*/
public static function groupContact($groupID, $contactIDs, $op) {
$config = CRM_Core_Config::singleton();
$ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE);
$ogID = CRM_Bridge_OG_Utils::ogID($groupID);

if (!$ogID) {
return;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Bridge/OG/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static function og(&$params, $op) {

$contactID = CRM_Bridge_OG_Utils::contactID($params['uf_id']);
if (!$contactID) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception(' no contact found');
}

// get the group id of this OG
Expand Down
12 changes: 4 additions & 8 deletions CRM/Bridge/OG/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ public static function ogSyncACLName($ogID) {

/**
* @param int $groupID
* @param bool $abort
*
* @return int|null|string
* @throws Exception
*/
public static function ogID($groupID, $abort = TRUE) {
public static function ogID($groupID) {
$source = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group',
$groupID,
'source'
Expand All @@ -73,9 +72,6 @@ public static function ogID($groupID, $abort = TRUE) {
return $matches[1];
}
}
if ($abort) {
CRM_Core_Error::fatal();
}
return NULL;
}

Expand All @@ -97,7 +93,7 @@ public static function contactID($ufID) {
CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $ufID, $account->mail, 'Drupal');
$contactID = CRM_Core_BAO_UFMatch::getContactId($ufID);
if (!$contactID) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('no contact found');
}
return $contactID;
}
Expand All @@ -108,7 +104,7 @@ public static function contactID($ufID) {
* @param bool $abort
*
* @return null|string
* @throws Exception
* @throws \CRM_Core_Exception
*/
public static function groupID($source, $title = NULL, $abort = FALSE) {
$query = "
Expand All @@ -126,7 +122,7 @@ public static function groupID($source, $title = NULL, $abort = FALSE) {
if ($abort &&
!$groupID
) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('no group found');
}

return $groupID;
Expand Down
4 changes: 2 additions & 2 deletions CRM/Extension/Manager/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function onPostInstall(CRM_Extension_Info $info) {
public function onPreUninstall(CRM_Extension_Info $info) {
$paymentProcessorTypes = $this->_getAllPaymentProcessorTypes('class_name');
if (!array_key_exists($info->key, $paymentProcessorTypes)) {
CRM_Core_Error::fatal(ts('This payment processor type is not registered.'));
throw new CRM_Core_Exception(ts('This payment processor type is not registered.'));
}

$dao = new CRM_Financial_DAO_PaymentProcessor();
Expand Down Expand Up @@ -229,7 +229,7 @@ private function _runPaymentHook(CRM_Extension_Info $info, $method) {
}

if (empty($class_name)) {
CRM_Core_Error::fatal("Unable to find payment processor in " . __CLASS__ . '::' . __METHOD__);
throw new CRM_Core_Exception('Unable to find payment processor in ' . __CLASS__ . '::' . __METHOD__);
}

// In the case of uninstall, check for instances of PP first.
Expand Down
4 changes: 2 additions & 2 deletions CRM/Extension/Manager/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public function onPreInstall(CRM_Extension_Info $info) {
public function onPreUninstall(CRM_Extension_Info $info) {
$customSearchesByName = $this->getCustomSearchesByName();
if (!array_key_exists($info->key, $customSearchesByName)) {
CRM_Core_Error::fatal('This custom search is not registered.');
throw new CRM_Core_Exception('This custom search is not registered.');
}

$cs = $this->getCustomSearchesById();
$id = $cs[$customSearchesByName[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::del($id);
CRM_Core_BAO_OptionValue::del($id);

return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Financial/BAO/FinancialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public static function checkPermissionedLineItems($id, $op, $force = TRUE) {
foreach ($lineItems as $items) {
if (!CRM_Core_Permission::check($op . ' contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
if ($force) {
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.'));
break;
}
$flag = FALSE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/PCP/BAO/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ public static function getOwnerNotificationId($component_id, $component = 'contr
WHERE pb.entity_id = %1 AND pb.entity_table = %2";
$params = [1 => [$component_id, 'Integer'], 2 => [$entity_table, 'String']];
if (!$ownerNotificationId = CRM_Core_DAO::singleValueQuery($query, $params)) {
CRM_Core_Error::fatal(ts('Owner Notification is not set for this Personal Campaign Page. Please contact the site administrator if you need assistance.'));
throw new CRM_Core_Exception(ts('Owner Notification is not set for this Personal Campaign Page. Please contact the site administrator if you need assistance.'));
}
else {
return $ownerNotificationId;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ public static function sendAcknowledgment(&$form, $params) {
}

if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) {
CRM_Core_Error::fatal("Failed creating Activity for acknowledgment");
throw new CRM_Core_Exception('Failed creating Activity for acknowledgment');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Pledge/BAO/PledgeBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static function buildPledgeBlock($form) {
}
// give error if empty or build form for payment.
if (empty($payments)) {
CRM_Core_Error::fatal(ts("Oops. It looks like there is no valid payment status for online payment."));
throw new CRM_Core_Exception(ts('Oops. It looks like there is no valid payment status for online payment.'));
}
else {
$form->assign('is_pledge_payment', TRUE);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1670,8 +1670,8 @@ protected static function reformatUsedByFormsWithEntityData($forms) {
break;

default:
CRM_Core_Error::fatal("$table is not supported in PriceSet::usedBy()");
break;
throw new CRM_Core_Exception("$table is not supported in PriceSet::usedBy()");

}
}
return $usedBy;
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ public function testCheckPermissionedLineItems() {
CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
$this->fail('Missed expected exception');
}
catch (Exception $e) {
$this->assertEquals('A fatal error was triggered: You do not have permission to access this page.', $e->getMessage());
catch (CRM_Core_Exception $e) {
$this->assertEquals('You do not have permission to access this page.', $e->getMessage());
}

$this->setPermissions([
Expand Down