function simplenews_mail_attempt_immediate_send in Simplenews 7
Same name and namespace in other branches
- 7.2 includes/simplenews.mail.inc \simplenews_mail_attempt_immediate_send()
Send mail spool immediatly if cron should not be used.
Parameters
$conditions: (Optional) Array of spool conditions which are applied to the query.
3 calls to simplenews_mail_attempt_immediate_send()
- SimplenewsSendTestCase::testSendPublishNoCron in tests/
simplenews.test - Send a newsletter on publish without using cron.
- simplenews_issue_send in includes/
simplenews.admin.inc - Callback to send newsletters.
- simplenews_node_tab_send_form_submit in includes/
simplenews.admin.inc - @todo
File
- includes/
simplenews.mail.inc, line 51 - Simplenews email send and spool handling
Code
function simplenews_mail_attempt_immediate_send(array $conditions = array(), $use_batch = TRUE) {
if (variable_get('simplenews_use_cron', TRUE)) {
return FALSE;
}
if ($use_batch) {
// Set up as many send operations as necessary to send all mails with the
// defined throttle amount.
$throttle = variable_get('simplenews_throttle', 20);
$spool_count = simplenews_count_spool($conditions);
$num_operations = ceil($spool_count / $throttle);
$operations = array();
for ($i = 0; $i < $num_operations; $i++) {
$operations[] = array(
'simplenews_mail_spool',
array(
$throttle,
$conditions,
),
);
}
// Add separate operations to clear the spool and updat the send status.
$operations[] = array(
'simplenews_clear_spool',
array(),
);
$operations[] = array(
'simplenews_send_status_update',
array(),
);
$batch = array(
'operations' => $operations,
'title' => t('Sending mails'),
'file' => drupal_get_path('module', 'simplenews') . '/includes/simplenews.mail.inc',
);
batch_set($batch);
}
else {
// Send everything that matches the conditions immediatly.
simplenews_mail_spool(SIMPLENEWS_UNLIMITED, $conditions);
simplenews_clear_spool();
simplenews_send_status_update();
}
return TRUE;
}