Skip to content

Commit

Permalink
Merge pull request #16746 from eileenmcnaughton/fatal
Browse files Browse the repository at this point in the history
[REF] Remove calls to fatal()
  • Loading branch information
seamuslee001 authored Mar 16, 2020
2 parents adec7a2 + 8f86a9e commit ffdf4f9
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions CRM/Core/BAO/MessageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate {
* @param array $defaults
* (reference ) an assoc array to hold the flattened values.
*
* @return CRM_Core_BAO_MessageTemplate
* @return CRM_Core_DAO_MessageTemplate
*/
public static function retrieve(&$params, &$defaults) {
$messageTemplates = new CRM_Core_DAO_MessageTemplate();
Expand Down Expand Up @@ -65,6 +65,8 @@ public static function setIsActive($id, $is_active) {
*
*
* @return object
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public static function add(&$params) {
// System Workflow Templates have a specific wodkflow_id in them but normal user end message templates don't
Expand All @@ -88,7 +90,7 @@ public static function add(&$params) {
if (!empty($params['workflow_id']) && !CRM_Core_Permission::check('edit system workflow message templates')) {
throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $systemWorkflowPermissionDeniedMessage]));
}
elseif (!CRM_Core_Permission::check('edit user-driven message templates')) {
if (!CRM_Core_Permission::check('edit user-driven message templates')) {
throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $userWorkflowPermissionDeniedMessage]));
}
}
Expand Down Expand Up @@ -129,11 +131,13 @@ public static function add(&$params) {
* Delete the Message Templates.
*
* @param int $messageTemplatesID
*
* @throws \CRM_Core_Exception
*/
public static function del($messageTemplatesID) {
// make sure messageTemplatesID is an integer
if (!CRM_Utils_Rule::positiveInteger($messageTemplatesID)) {
CRM_Core_Error::fatal(ts('Invalid Message template'));
throw new CRM_Core_Exception(ts('Invalid Message template'));
}

// Set mailing msg template col to NULL
Expand All @@ -158,7 +162,7 @@ public static function del($messageTemplatesID) {
*
* @param bool $isSMS
*
* @return object
* @return array
*/
public static function getMessageTemplates($all = TRUE, $isSMS = FALSE) {
$msgTpls = [];
Expand All @@ -185,6 +189,7 @@ public static function getMessageTemplates($all = TRUE, $isSMS = FALSE) {
* @param $from
*
* @return bool|NULL
* @throws \CRM_Core_Exception
*/
public static function sendReminder($contactId, $email, $messageTemplateID, $from) {

Expand Down Expand Up @@ -301,14 +306,16 @@ public static function sendReminder($contactId, $email, $messageTemplateID, $fro
* Revert a message template to its default subject+text+HTML state.
*
* @param int $id id of the template
*
* @throws \CRM_Core_Exception
*/
public static function revert($id) {
$diverted = new CRM_Core_BAO_MessageTemplate();
$diverted->id = (int) $id;
$diverted->find(1);

if ($diverted->N != 1) {
CRM_Core_Error::fatal(ts('Did not find a message template with id of %1.', [1 => $id]));
throw new CRM_Core_Exception(ts('Did not find a message template with id of %1.', [1 => $id]));
}

$orig = new CRM_Core_BAO_MessageTemplate();
Expand All @@ -317,7 +324,7 @@ public static function revert($id) {
$orig->find(1);

if ($orig->N != 1) {
CRM_Core_Error::fatal(ts('Message template with id of %1 does not have a default to revert to.', [1 => $id]));
throw new CRM_Core_Exception(ts('Message template with id of %1 does not have a default to revert to.', [1 => $id]));
}

$diverted->msg_subject = $orig->msg_subject;
Expand All @@ -335,6 +342,7 @@ public static function revert($id) {
*
* @return array
* Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
* @throws \CRM_Core_Exception
*/
public static function sendTemplate($params) {
$defaults = [
Expand Down Expand Up @@ -381,7 +389,7 @@ public static function sendTemplate($params) {
) &&
!$params['messageTemplateID']
) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
throw new CRM_Core_Exception(ts("Message template's option group and/or option value or ID missing."));
}

if ($params['messageTemplateID']) {
Expand All @@ -405,14 +413,12 @@ public static function sendTemplate($params) {

if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', [1 => $params['messageTemplateID']]));
}
else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', [
1 => $params['groupName'],
2 => $params['valueName'],
]));
throw new CRM_Core_Exception(ts('No such message template: id=%1.', [1 => $params['messageTemplateID']]));
}
throw new CRM_Core_Exception(ts('No such message template: option group %1, option value %2.', [
1 => $params['groupName'],
2 => $params['valueName'],
]));
}

$mailContent = [
Expand Down Expand Up @@ -545,11 +551,11 @@ public static function sendTemplate($params) {

$prefs = array_pop($contact);

if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'HTML') {
if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] === 'HTML') {
$params['text'] = NULL;
}

if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'Text') {
if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] === 'Text') {
$params['html'] = NULL;
}

Expand Down

0 comments on commit ffdf4f9

Please sign in to comment.