You are here

function drush_simplenews_spool_send in Simplenews 3.x

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

Drush command to send the mail spool queue.

File

./simplenews.drush.inc, line 62
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([
      'p',
      'pipe',
    ])) {

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