-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev/core#3177 Switch sms to use flexmailer token rendering
- Loading branch information
1 parent
45e2237
commit b7146b3
Showing
7 changed files
with
117 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
/** | ||
* Job for SMS deliery functions. | ||
*/ | ||
class CRM_Mailing_BAO_SMSJob extends CRM_Mailing_BAO_MailingJob { | ||
|
||
/** | ||
* This is used by CiviMail but will be made redundant by FlexMailer. | ||
* @param array $fields | ||
* List of intended recipients. | ||
* Each recipient is an array with keys 'hash', 'contact_id', 'email', etc. | ||
* @param $mailing | ||
* @param $mailer | ||
* @param $job_date | ||
* @param $attachments | ||
* | ||
* @return bool|null | ||
* @throws Exception | ||
*/ | ||
public function deliverGroup(&$fields, &$mailing, &$mailer, &$job_date, &$attachments) { | ||
$count = 0; | ||
// dev/core#1768 Get the mail sync interval. | ||
$mail_sync_interval = Civi::settings()->get('civimail_sync_interval'); | ||
$retryGroup = FALSE; | ||
|
||
foreach ($fields as $field) { | ||
$contact = civicrm_api3('Contact', 'getsingle', ['id' => $field['contact_id']]); | ||
|
||
$preview = civicrm_api3('Mailing', 'preview', [ | ||
'id' => $mailing->id, | ||
'contact_id' => $field['contact_id'], | ||
])['values']; | ||
$mailParams = [ | ||
'text' => $preview['body_text'], | ||
'toName' => $contact['display_name'], | ||
'job_id' => $this->id, | ||
]; | ||
CRM_Utils_Hook::alterMailParams($mailParams, 'civimail'); | ||
$body = $mailParams['text']; | ||
$headers = ['To' => $field['phone']]; | ||
|
||
try { | ||
$result = $mailer->send($headers['To'], $headers, $body, $this->id); | ||
|
||
// Register the delivery event. | ||
$deliveredParams[] = $field['id']; | ||
$targetParams[] = $field['contact_id']; | ||
|
||
$count++; | ||
// dev/core#1768 Mail sync interval is now configurable. | ||
if ($count % $mail_sync_interval == 0) { | ||
$this->writeToDB( | ||
$deliveredParams, | ||
$targetParams, | ||
$mailing, | ||
$job_date | ||
); | ||
$count = 0; | ||
|
||
// hack to stop mailing job at run time, CRM-4246. | ||
// to avoid making too many DB calls for this rare case | ||
// lets do it when we snapshot | ||
$status = CRM_Core_DAO::getFieldValue( | ||
'CRM_Mailing_DAO_MailingJob', | ||
$this->id, | ||
'status', | ||
'id', | ||
TRUE | ||
); | ||
|
||
if ($status !== 'Running') { | ||
return FALSE; | ||
} | ||
} | ||
} | ||
catch (CRM_Core_Exception $e) { | ||
// Handle SMS errors: CRM-15426 | ||
$job_id = (int) $this->id; | ||
$mailing_id = (int) $mailing->id; | ||
CRM_Core_Error::debug_log_message("Failed to send SMS message. Vars: mailing_id: ${mailing_id}, job_id: ${job_id}. Error message follows."); | ||
CRM_Core_Error::debug_log_message($e->getMessage()); | ||
} | ||
|
||
unset($result); | ||
|
||
// If we have enabled the Throttle option, this is the time to enforce it. | ||
$mailThrottleTime = Civi::settings()->get('mailThrottleTime'); | ||
if (!empty($mailThrottleTime)) { | ||
usleep((int ) $mailThrottleTime); | ||
} | ||
} | ||
|
||
$result = $this->writeToDB( | ||
$deliveredParams, | ||
$targetParams, | ||
$mailing, | ||
$job_date | ||
); | ||
|
||
if ($retryGroup) { | ||
return FALSE; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters