function drush_queue_mail_send_all in Queue Mail 7
Drush command to dequeue and send all emails.
File
- ./
queue_mail.drush.inc, line 34 - Drush integration for the Queue Mail module.
Code
function drush_queue_mail_send_all() {
$sent_mails_count = 0;
// Prevent session information from being saved while queue is running.
drupal_save_session(FALSE);
// Force the current user to anonymous to ensure consistent permissions on
// queue runs.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
// Grab the defined cron queues.
$queues = module_invoke_all('cron_queue_info');
drupal_alter('cron_queue_info', $queues);
// And fetch and process our queue.
$queue_name = QUEUE_MAIL_QUEUE_NAME;
if (isset($queues[$queue_name])) {
$info = $queues[$queue_name];
$function = $info['worker callback'];
$timeout = drush_get_option('timeout', 0);
$end = time() + $timeout;
$queue = _queue_mail_get_queue();
while (($timeout == 0 || time() < $end) && ($item = $queue
->claimItem())) {
try {
$function($item->data);
$queue
->deleteItem($item);
$sent_mails_count++;
} catch (Exception $e) {
// In case of exception log it and leave the item in the queue
// to be processed again later.
watchdog_exception('queue_mail', $e);
}
}
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
drush_log(dt('Processed @count queued items.', array(
'@count' => $sent_mails_count,
)), 'ok');
}