Skip to content

Commit

Permalink
dev/core#560 Convert final CRM_Core_Error::fatal to statusBounces or …
Browse files Browse the repository at this point in the history
…Exceptions
  • Loading branch information
seamuslee001 committed Jun 8, 2020
1 parent d78a2f7 commit 79e1180
Show file tree
Hide file tree
Showing 42 changed files with 54 additions and 59 deletions.
3 changes: 1 addition & 2 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,7 @@ public static function addActivity(
// @todo - use api - remove lots of wrangling above. Remove deprecated fatal & let form layer
// deal with any exceptions.
if (is_a(self::create($activityParams), 'CRM_Core_Error')) {
CRM_Core_Error::fatal("Failed creating Activity for $component of id {$activity->id}");
return FALSE;
throw new CRM_Core_Exception("Failed creating Activity for $component of id {$activity->id}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function run(
$totalRowCount = NULL
) {
if (!is_array($fileName)) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Unable to determine import file');
}
$fileName = $fileName['name'];

Expand Down
6 changes: 3 additions & 3 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ public function restWhere(&$values) {
}
// we don't know when this might happen
else {
CRM_Core_Error::fatal(ts("%1 is not a valid operator", [1 => $operator]));
throw new CRM_Core_Exception(ts("%1 is not a valid operator", [1 => $operator]));
}
}
}
Expand Down Expand Up @@ -2417,7 +2417,7 @@ public static function getLocationTableName(&$where, &$locType) {
$tName = str_replace(' ', '_', $tName);
return [$tName, $fldName];
}
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Cannot determine location table information');
}

/**
Expand Down Expand Up @@ -2973,7 +2973,7 @@ public function group($values) {

if (is_array($value) && count($value) > 1) {
if (strpos($op, 'IN') === FALSE && strpos($op, 'NULL') === FALSE) {
CRM_Core_Error::fatal(ts("%1 is not a valid operator", [1 => $op]));
throw new CRM_Core_Exception(ts("%1 is not a valid operator", [1 => $op]));
}
$this->_useDistinct = TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ public static function transitionComponents($params, $processContributionObject
$ids['contributionPage'] = NULL;

if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Unable to validate supplied data');
}

$memberships = &$objects['membership'];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ public function invalidKey() {

public function invalidKeyCommon() {
$msg = ts("We can't load the requested web page. This page requires cookies to be enabled in your browser settings. Please check this setting and enable cookies (if they are not enabled). Then try again. If this error persists, contact the site administrator for assistance.") . '<br /><br />' . ts('Site Administrators: This error may indicate that users are accessing this page using a domain or URL other than the configured Base URL. EXAMPLE: Base URL is http://example.org, but some users are accessing the page via http://www.example.org or a domain alias like http://myotherexample.org.') . '<br /><br />' . ts('Error type: Could not find a valid session key.');
CRM_Core_Error::fatal($msg);
throw new CRM_Core_Exception($msg);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/IDS.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private function kick() {
);
CRM_Utils_JSON::output($error);
}
CRM_Core_Error::fatal($msg);
throw new CRM_Core_Exception($msg);
}

}
2 changes: 1 addition & 1 deletion CRM/Core/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private function _getJobs() {
*/
private function _getJob($id = NULL, $entity = NULL, $action = NULL) {
if (is_null($id) && is_null($action)) {
CRM_Core_Error::fatal('You need to provide either id or name to use this method');
throw new CRM_Core_Exception('You need to provide either id or name to use this method');
}
$dao = new CRM_Core_DAO_Job();
$dao->id = $id;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function run() {
}

if (!$className) {
CRM_Core_Error::fatal(ts('Invalid className: %1', [1 => $className]));
throw new CRM_Core_Exception(ts('Invalid className: %1', [1 => $className]));
}

$fnName = NULL;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Page/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function run($path = NULL, $pageArgs = []) {
*/
public static function createUrl($requestPath, $requestArgs, $pageArgs, $absolute) {
if (empty($pageArgs['url'])) {
CRM_Core_Error::fatal('This page is configured as a redirect, but it does not have a target.');
CRM_Core_Error::statusBounce('This page is configured as a redirect, but it does not have a target.');
}

$vars = [];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public static function checkMenu(&$args, $op = 'and') {
public static function checkMenuItem(&$item) {
if (!array_key_exists('access_callback', $item)) {
CRM_Core_Error::backtrace();
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Missing Access Callback key in menu item');
}

// if component_id is present, ensure it is enabled
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public function render($default, $allowCmsOverride = TRUE) {
break;

default:
require_once 'CRM/Core/Error.php';
CRM_Core_Error::fatal(ts('Snippet type %1 is unrecognized',
require_once 'CRM/Core/Exception.php';
throw new CRM_Core_Exception(ts('Snippet type %1 is unrecognized',
[1 => $snippet['type']]));
}
}
Expand Down
3 changes: 0 additions & 3 deletions CRM/Core/Selector/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ public function &getSortOrder($action) {
unset($header);
}
}
if ($firstElementNotFound) {
// CRM_Core_Error::fatal( "Could not find a valid sort directional element" );
}
}
return $this->_order;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Form/ChangeFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function preProcess() {
);

if (empty($this->_values) || empty($this->_htmlTypeTransitions)) {
CRM_Core_Error::fatal(ts("Invalid custom field or can't change input type of this custom field."));
CRM_Core_Error::statusBounce(ts("Invalid custom field or can't change input type of this custom field."));
}

$url = CRM_Utils_System::url('civicrm/admin/custom/group/field/update',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function preProcess() {
}

if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
CRM_Core_Error::statusBounce("You cannot add or edit fields in a reserved custom field-set.");
}

if ($this->_gid) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function preProcess() {
}

if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit muliple choice options in a reserved custom field-set.");
CRM_Core_Error::statusBounce("You cannot add or edit muliple choice options in a reserved custom field-set.");
}

$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function run(
$onDuplicate = self::DUPLICATE_SKIP
) {
if (!is_array($fileName)) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Unable to determine import file');
}
$fileName = $fileName['name'];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Page/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function run() {
}

if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
CRM_Core_Error::statusBounce("You cannot add or edit fields in a reserved custom field-set.");
}

$action = CRM_Utils_Request::retrieve('action', 'String',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Page/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function run() {
);

if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit multiple choice options in a reserved custom field-set.");
CRM_Core_Error::statusBounce("You cannot add or edit multiple choice options in a reserved custom field-set.");
}

$optionGroupId = $this->getOptionGroupId($this->_fid);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/BAO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ public static function sendTransitionParticipantMail(
];

if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) {
CRM_Core_Error::fatal('Failed creating Activity for expiration mail');
throw new CRM_Core_Exception('Failed creating Activity for expiration mail');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/BAO/ParticipantPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function deleteParticipantPayment($params) {
}

if (!$valid) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Cannot delete participant payment');
}

if ($participantPayment->find(TRUE)) {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/Cart/BAO/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function create($params) {

if (is_a($cart, 'CRM_Core_Error')) {
$transaction->rollback();
CRM_Core_Error::fatal(ts('There was an error creating an event cart'));
throw new CRM_Core_Exception(ts('There was an error creating an event cart'));
}

$transaction->commit();
Expand Down Expand Up @@ -324,7 +324,7 @@ public function get_participant_index_from_id($participant_id) {
public static function retrieve(&$params, &$values) {
$cart = self::find_by_params($params);
if ($cart === FALSE) {
CRM_Core_Error::fatal(ts('Could not find cart matching %1', [1 => var_export($params, TRUE)]));
throw new CRM_Core_Exception(ts('Could not find cart matching %1', [1 => var_export($params, TRUE)]));
}
CRM_Core_DAO::storeValues($cart, $values);
return $values;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Cart/BAO/EventInCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function create(&$params) {

if (is_a($event_in_cart, 'CRM_Core_Error')) {
$transaction->rollback();
CRM_Core_Error::fatal(ts('There was an error creating an event_in_cart'));
throw new CRM_Core_Exception(ts('There was an error creating an event_in_cart'));
}

$transaction->commit();
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/ManageEvent/Repeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function postProcess() {
CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
}
else {
CRM_Core_Error::fatal("Could not find Event ID");
CRM_Core_Error::statusBounce("Could not find Event ID");
}
parent::endPostProcess();
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/ManageEvent/TabHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function process(&$form) {
];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
if (!$dao->fetch()) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Unable to determine Event information');;
}
if (!$dao->is_location) {
$tabs['location']['valid'] = FALSE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public static function initEventFee(&$form, $eventID, $includeExpiredFields = TR
}
if ($isPaidEvent && empty($form->_values['fee'])) {
if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') {
CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId))));
CRM_Core_Error::statusBounce(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId))));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function run(
$onDuplicate = self::DUPLICATE_SKIP
) {
if (!is_array($fileName)) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Unable to determine import file');
}
$fileName = $fileName['name'];

Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/Page/ParticipantListing.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function run() {
)
);
if ($className == 'CRM_Event_Page_ParticipantListing') {
CRM_Core_Error::fatal(ts("Participant listing code file cannot be '%1'",
CRM_Core_Error::statusBounce(ts("Participant listing code file cannot be '%1'",
array(1 => $className)
));
}
Expand All @@ -77,7 +77,7 @@ public function run() {
) . '.php';
$error = include_once $classFile;
if ($error == FALSE) {
CRM_Core_Error::fatal('Participant listing code file: ' . $classFile . ' does not exist. Please verify your custom particpant listing settings in CiviCRM administrative panel.');
CRM_Core_Error::statusBounce('Participant listing code file: ' . $classFile . ' does not exist. Please verify your custom particpant listing settings in CiviCRM administrative panel.');
}

$participantListingClass = new $className();
Expand Down
3 changes: 1 addition & 2 deletions CRM/Financial/Page/FinancialTypeAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ public function browse() {
$this->assign('financialTypeTitle', $this->_title);
}
else {
CRM_Core_Error::fatal();
return NULL;
CRM_Core_Error::statusBounce('No Financial Accounts found for the Financial Type');
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Form/Task/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function buildQuickForm() {
$ufGroupId = $this->get('ufGroupId');

if (!$ufGroupId) {
CRM_Core_Error::fatal('ufGroupId is missing');
CRM_Core_Error::statusBounce('ufGroupId is missing');
}
$this->_title = ts('Update multiple memberships') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
CRM_Utils_System::setTitle($this->_title);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function run(
$totalRowCount = NULL
) {
if (!is_array($fileName)) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Unable to determine import file');
}
$fileName = $fileName['name'];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Page/DashBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function preProcess() {
!checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
substr($ym, 0, 1) == 0
) {
CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
CRM_Core_Error::statusBounce(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
}

$isPreviousMonth = 0;
Expand Down
4 changes: 2 additions & 2 deletions CRM/PCP/BAO/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE,

if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
$fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', [1 => $fixUrl]));
throw new CRM_Core_Exception(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', [1 => $fixUrl]));
}

$receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
Expand Down Expand Up @@ -913,7 +913,7 @@ public static function getSupporterProfileId($component_id, $component = 'contri

$params = [1 => [$component_id, 'Integer'], 2 => [$entity_table, 'String']];
if (!$supporterProfileId = CRM_Core_DAO::singleValueQuery($query, $params)) {
CRM_Core_Error::fatal(ts('Supporter profile is not set for this Personal Campaign Page or the profile is disabled. Please contact the site administrator if you need assistance.'));
throw new CRM_Core_Exception(ts('Supporter profile is not set for this Personal Campaign Page or the profile is disabled. Please contact the site administrator if you need assistance.'));
}
else {
return $supporterProfileId;
Expand Down
2 changes: 1 addition & 1 deletion CRM/PCP/Form/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function postProcess() {

if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
$fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', [1 => $fixUrl]));
CRM_Core_Error::statusBounce(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', [1 => $fixUrl]));
}

//if more than one email present for PCP notification ,
Expand Down
4 changes: 2 additions & 2 deletions CRM/PCP/Form/PCPAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public function preProcess() {
if (!$this->_pageId) {
if (!$this->_id) {
$msg = ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.');
CRM_Core_Error::fatal($msg);
CRM_Core_Error::statusBounce($msg);
}
else {
$this->_pageId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'page_id');
}
}

if (!$this->_pageId) {
CRM_Core_Error::fatal(ts('Could not find source page id.'));
CRM_Core_Error::statusBounce(ts('Could not find source page id.'));
}

$this->_single = $this->get('single');
Expand Down
2 changes: 1 addition & 1 deletion CRM/Price/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function buildQuickForm() {
if ($this->_action == CRM_Core_Action::UPDATE) {
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_oid, 'financial_type_id');
if (!CRM_Financial_BAO_FinancialType::checkPermissionToEditFinancialType($finTypeId)) {
CRM_Core_Error::fatal(ts("You do not have permission to access this page"));
CRM_Core_Error::statusBounce(ts("You do not have permission to access this page"));
}
}
if ($this->_action == CRM_Core_Action::DELETE) {
Expand Down
Loading

0 comments on commit 79e1180

Please sign in to comment.