4 * Job for SMS deliery functions.
6 class CRM_Mailing_BAO_SMSJob
extends CRM_Mailing_BAO_MailingJob
{
9 * This is used by CiviMail but will be made redundant by FlexMailer.
10 * @param array $fields
11 * List of intended recipients.
12 * Each recipient is an array with keys 'hash', 'contact_id', 'email', etc.
21 public function deliverGroup(&$fields, &$mailing, &$mailer, &$job_date, &$attachments) {
23 // dev/core#1768 Get the mail sync interval.
24 $mail_sync_interval = Civi
::settings()->get('civimail_sync_interval');
27 foreach ($fields as $field) {
28 $contact = civicrm_api3('Contact', 'getsingle', ['id' => $field['contact_id']]);
30 $preview = civicrm_api3('Mailing', 'preview', [
32 'contact_id' => $field['contact_id'],
35 'text' => $preview['body_text'],
36 'toName' => $contact['display_name'],
37 'job_id' => $this->id
,
39 CRM_Utils_Hook
::alterMailParams($mailParams, 'civimail');
40 $body = $mailParams['text'];
41 $headers = ['To' => $field['phone']];
44 $result = $mailer->send($headers['To'], $headers, $body, $this->id
);
46 // Register the delivery event.
47 $deliveredParams[] = $field['id'];
48 $targetParams[] = $field['contact_id'];
51 // dev/core#1768 Mail sync interval is now configurable.
52 if ($count %
$mail_sync_interval == 0) {
61 // hack to stop mailing job at run time, CRM-4246.
62 // to avoid making too many DB calls for this rare case
63 // lets do it when we snapshot
64 $status = CRM_Core_DAO
::getFieldValue(
65 'CRM_Mailing_DAO_MailingJob',
72 if ($status !== 'Running') {
77 catch (CRM_Core_Exception
$e) {
78 // Handle SMS errors: CRM-15426
79 $job_id = (int) $this->id
;
80 $mailing_id = (int) $mailing->id
;
81 CRM_Core_Error
::debug_log_message("Failed to send SMS message. Vars: mailing_id: ${mailing_id}, job_id: ${job_id}. Error message follows.");
82 CRM_Core_Error
::debug_log_message($e->getMessage());
87 // If we have enabled the Throttle option, this is the time to enforce it.
88 $mailThrottleTime = Civi
::settings()->get('mailThrottleTime');
89 if (!empty($mailThrottleTime)) {
90 usleep((int ) $mailThrottleTime);
94 $result = $this->writeToDB(