$errMsgs[] = PEAR::raiseError('Contact Does not accept SMS', NULL, PEAR_ERROR_RETURN);
}
else {
- $sendResult = self::sendSMSMessage(
- $contactId,
- $tokenText,
- $smsProviderParams,
- $activityID,
- $sourceContactId
- );
-
- if (PEAR::isError($sendResult)) {
- // Collect all of the PEAR_Error objects
- $errMsgs[] = $sendResult;
- }
- else {
+ try {
+ $sendResult = self::sendSMSMessage(
+ $contactId,
+ $tokenText,
+ $smsProviderParams,
+ $activityID,
+ $sourceContactId
+ );
$success++;
}
+ catch (CRM_Core_Exception $e) {
+ $errMsgs[] = $e->getMessage();
+ }
}
}
* The activity ID that tracks the message.
* @param int $sourceContactID
*
- * @return bool|PEAR_Error
- * true on success or PEAR_Error object
+ * @return bool true on success
+ * @throws CRM_Core_Exception
*/
public static function sendSMSMessage(
$toID,
// make sure both phone are valid
// and that the recipient wants to receive sms
if (empty($toPhoneNumber)) {
- return PEAR::raiseError(
- 'Recipient phone number is invalid or recipient does not want to receive SMS',
- NULL,
- PEAR_ERROR_RETURN
- );
+ throw new CRM_Core_Exception('Recipient phone number is invalid or recipient does not want to receive SMS');
}
$recipient = $toPhoneNumber;
$providerObj = CRM_SMS_Provider::singleton(['provider_id' => $smsProviderParams['provider_id']]);
$sendResult = $providerObj->send($recipient, $smsProviderParams, $tokenText, NULL, $sourceContactID);
if (PEAR::isError($sendResult)) {
- return $sendResult;
+ throw new CRM_Core_Exception($sendResult->getMessage());
}
// add activity target record for every sms that is sent
$activity = CRM_Activity_BAO_Activity::create($activityParams);
- CRM_Activity_BAO_Activity::sendSMSMessage($tokenRow->context['contactId'],
- $sms_body_text,
- $smsParams,
- $activity->id,
- $userID
- );
+ try {
+ CRM_Activity_BAO_Activity::sendSMSMessage($tokenRow->context['contactId'],
+ $sms_body_text,
+ $smsParams,
+ $activity->id,
+ $userID
+ );
+ }
+ catch (CRM_Core_Exception $e) {
+ return ["sms_send_error" => $e->getMessage()];
+ }
return [];
}
* @param int $providerID
*
* @return null
- * @throws Exception
+ * @throws CRM_Core_Exception
*/
public static function del($providerID) {
if (!$providerID) {
- CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
+ throw new CRM_Core_Exception(ts('Invalid value passed to delete function.'));
}
$dao = new CRM_SMS_DAO_Provider();
*/
public function preProcess() {
if (!CRM_SMS_BAO_Provider::activeProviderCount()) {
- CRM_Core_Error::fatal(ts('The <a href="%1">SMS Provider</a> has not been configured or is not active.', [1 => CRM_Utils_System::url('civicrm/admin/sms/provider', 'reset=1')]));
+ CRM_Core_Error::statusBounce(ts('The <a href="%1">SMS Provider</a> has not been configured or is not active.', [1 => CRM_Utils_System::url('civicrm/admin/sms/provider', 'reset=1')]));
}
$session = CRM_Core_Session::singleton();
$params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID;
if (empty($params['mailing_id'])) {
- CRM_Core_Error::fatal(ts('Could not find a mailing id'));
+ CRM_Core_Error::statusBounce(ts('Could not find a mailing id'));
}
$params['send_option'] = $this->controller->exportValue($this->_name, 'send_option');
* @param bool $force
*
* @return object
+ * @throws CRM_Core_Exception
*/
public static function &singleton($providerParams = array(), $force = FALSE) {
$mailingID = CRM_Utils_Array::value('mailing_id', $providerParams);
}
if (!$providerName) {
- CRM_Core_Error::fatal('Provider not known or not provided.');
+ throw new CRM_Core_Exception('Provider not known or not provided.');
}
$providerName = CRM_Utils_Type::escape($providerName, 'String');
else {
// If we are running unit tests we simulate an SMS provider with the name "CiviTestSMSProvider"
if ($providerName !== 'CiviTestSMSProvider') {
- CRM_Core_Error::fatal("Could not locate extension for {$providerName}.");
+ throw new CRM_Core_Exception("Could not locate extension for {$providerName}.");
}
$providerClass = 'CiviTestSMSProvider';
}
$this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
$this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
$this->assertEquals($activity['details'], $details, 'Activity details does not match.');
- $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0]->message, "Expected error doesn't match");
+ $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0], "Expected error doesn't match");
$this->assertEquals(0, $success, "Expected success to be 0");
}
$this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
$this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
$this->assertEquals($activity['details'], $details, 'Activity details does not match.');
- $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0]->message, "Expected error doesn't match");
+ $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0], "Expected error doesn't match");
$this->assertEquals(0, $success, "Expected success to be 0");
}
public function testSendSMSMobileInToProviderParamWithDoNotSMS() {
list($sent, $activityId, $success) = $this->createSendSmsTest(2, TRUE, ['do_not_sms' => 1]);
foreach ($sent as $error) {
- $this->assertEquals('Contact Does not accept SMS', $error->getMessage());
+ $this->assertEquals('Contact Does not accept SMS', $error);
}
$this->assertEquals(1, count($sent), "Expected sent should a PEAR Error");
$this->assertEquals(0, $success, "Expected success to be 0");