*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
*/
require_once 'Mail.php';
*
* @param array $testParams
* @param null $mode
- *
- * @return void
*/
public static function runJobs($testParams = NULL, $mode = NULL) {
$job = new CRM_Mailing_BAO_MailingJob();
while ($job->fetch()) {
// still use job level lock for each child job
- $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.mailing.job.{$job->id}");
+ $lock = Civi::lockManager()->acquire("data.mailing.job.{$job->id}");
if (!$lock->isAcquired()) {
continue;
}
// Get the mailer
if ($mode === NULL) {
- $mailer = \Civi\Core\Container::singleton()->get('pear_mail');
+ $mailer = \Civi::service('pear_mail');
}
elseif ($mode == 'sms') {
$mailer = CRM_SMS_Provider::singleton(array('mailing_id' => $job->mailing_id));
// Mark the child complete
if ($isComplete) {
- /* Finish the job */
+ // Finish the job.
$transaction = new CRM_Core_Transaction();
}
/**
- * post process to determine if the parent job.
- * as well as the mailing is complete after the run
+ * Post process to determine if the parent job
+ * as well as the mailing is complete after the run.
* @param null $mode
*/
public static function runJobs_post($mode = NULL) {
$mailing->is_completed = TRUE;
$mailing->save();
$transaction->commit();
+
+ // CRM-17763
+ CRM_Utils_Hook::postMailing($job->mailing_id);
}
}
}
// X Number of child jobs
while ($job->fetch()) {
// still use job level lock for each child job
- $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.mailing.job.{$job->id}");
+ $lock = Civi::lockManager()->acquire("data.mailing.job.{$job->id}");
if (!$lock->isAcquired()) {
continue;
}
$recipients->phone_id,
);
$count++;
- if ($count % CRM_Core_DAO::BULK_MAIL_INSERT_COUNT == 0) {
+ if ($count % CRM_Mailing_Config::BULK_MAIL_INSERT_COUNT == 0) {
CRM_Mailing_Event_BAO_Queue::bulkCreate($params, $now);
$count = 0;
$params = array();
* A Mail object to send the messages.
*
* @param array $testParams
- *
- * @return void
*/
public function deliver(&$mailer, $testParams = NULL) {
$mailing = new CRM_Mailing_BAO_Mailing();
$config = CRM_Core_Config::singleton();
}
+ if (property_exists($mailing, 'language') && $mailing->language && $mailing->language != 'en_US') {
+ $swapLang = CRM_Utils_AutoClean::swap('global://dbLocale?getter', 'call://i18n/setLocale', $mailing->language);
+ }
+
$job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
$fields = array();
// CRM-12376
// This handles the edge case scenario where all the mails
- // have been delivered in prior jobs
+ // have been delivered in prior jobs.
$isDelivered = TRUE;
- // make sure that there's no more than $config->mailerBatchLimit mails processed in a run
+ // make sure that there's no more than $mailerBatchLimit mails processed in a run
+ $mailerBatchLimit = Civi::settings()->get('mailerBatchLimit');
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
// CRM_Utils_System::xMemory( "$mailsProcessed: " );
// }
- if (
- $config->mailerBatchLimit > 0 &&
- self::$mailsProcessed >= $config->mailerBatchLimit
- ) {
+ if ($mailerBatchLimit > 0 && self::$mailsProcessed >= $mailerBatchLimit) {
if (!empty($fields)) {
$this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
$params = $targetParams = $deliveredParams = array();
$count = 0;
- /**
- * CRM-15702: Sending bulk sms to contacts without e-mail address fails.
- * Solution is to skip checking for on hold
- */
- $skipOnHold = TRUE; //do include a statement to check wether e-mail address is on hold
+ // CRM-15702: Sending bulk sms to contacts without e-mail address fails.
+ // Solution is to skip checking for on hold
+ $skipOnHold = TRUE; //do include a statement to check wether e-mail address is on hold
if ($mailing->sms_provider_id) {
$skipOnHold = FALSE; //do not include a statement to check wether e-mail address is on hold
}
$details[0][$contactID] = array();
}
- /* Compose the mailing */
+ // Compose the mailing.
$recipient = $replyToEmail = NULL;
$replyValue = strcmp($mailing->replyto_email, $mailing->from_email);
if ($replyValue) {
continue;
}
- /* Send the mailing */
+ // Send the mailing.
$body = &$message->get();
$headers = &$message->headers();
CRM_Utils_System::civiExit();
}
- /* Register the bounce event */
+ // Register the bounce event.
$params = array(
'event_queue_id' => $field['id'],
CRM_Core_Error::debug_log_message($result->getMessage());
}
else {
- /* Register the delivery event */
+ // Register the delivery event.
$deliveredParams[] = $field['id'];
$targetParams[] = $field['contact_id'];
$count++;
- if ($count % CRM_Core_DAO::BULK_MAIL_INSERT_COUNT == 0) {
+ if ($count % CRM_Mailing_Config::BULK_MAIL_INSERT_COUNT == 0) {
$this->writeToDB(
$deliveredParams,
$targetParams,
}
// If we have enabled the Throttle option, this is the time to enforce it.
- if (isset($config->mailThrottleTime) && $config->mailThrottleTime > 0) {
- usleep((int ) $config->mailThrottleTime);
+ $mailThrottleTime = Civi::settings()->get('mailThrottleTime');
+ if (!empty($mailThrottleTime)) {
+ usleep((int ) $mailThrottleTime);
}
}
}
if ($writeActivity === NULL) {
- $writeActivity = CRM_Core_BAO_Setting::getItem(
- CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
- 'write_activity_record',
- NULL,
- TRUE
- );
+ $writeActivity = Civi::settings()->get('write_activity_record');
}
if (!$writeActivity) {