You are here

function drush_simplenews_spool_send in Simplenews 8

Same name and namespace in other branches
  1. 8.2 simplenews.drush.inc \drush_simplenews_spool_send()
  2. 7.2 simplenews.drush.inc \drush_simplenews_spool_send()
  3. 7 simplenews.drush.inc \drush_simplenews_spool_send()
  4. 3.x simplenews.drush.inc \drush_simplenews_spool_send()

Drush command to send the mail spool queue.

File

./simplenews.drush.inc, line 61
Drush commands for administer Simplenews.

Code

function drush_simplenews_spool_send($limit = FALSE) {
  if (!simplenews_assert_uri()) {
    drush_set_error('Site URI not specified, use --uri.');
    return;
  }
  if ($limit === FALSE) {
    $limit = \Drupal::config('simplenews.settings')
      ->get('mail.throttle');
  }
  elseif ($limit == 0) {
    $limit = SpoolStorageInterface::UNLIMITED;
  }
  $start_time = microtime(TRUE);
  $sent = \Drupal::service('simplenews.mailer')
    ->sendSpool($limit);
  \Drupal::service('simplenews.spool_storage')
    ->clear();
  \Drupal::service('simplenews.mailer')
    ->updateSendStatus();
  $durance = round(microtime(TRUE) - $start_time, 2);

  // Report the number of sent mails.
  if ($sent > 0) {
    $remaining = \Drupal::service('simplenews.spool_storage')
      ->countMails();
    if (drush_get_option(array(
      'p',
      'pipe',
    ))) {

      // For pipe, print the sent first and then the remaining count, separated by a space.
      drush_print_pipe($sent . " " . $remaining);
    }
    else {
      drush_log(dt('Sent @count mails from the queue in @sec seconds.', array(
        '@count' => $sent,
        '@sec' => $durance,
      )), 'status');
      drush_log(dt('Remaining simplenews mail spool count: @count', array(
        '@count' => $remaining,
      )), 'status');
    }
  }
}