public function SimplenewsCommands::spoolSend in Simplenews 3.x
Same name and namespace in other branches
- 8.2 src/Commands/SimplenewsCommands.php \Drupal\simplenews\Commands\SimplenewsCommands::spoolSend()
Send the defined amount of mail spool entries.
@usage drush sn-ss Send the default amount of mails, as defined by the mail.throttle settings. @usage drush sn-ss 0 Send all mails. @usage drush sn-ss 100 Send 100 mails.
@validate-module-enabled simplenews
@command simplenews:spool-send @aliases sn-ss,simplenews-spool-send
Parameters
int|bool $limit: Number of mails to send. 0 sends all emails. If not specified, will be set to the value of the mail.throttle in the module settings config.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
Throws
\Exception
File
- src/
Commands/ SimplenewsCommands.php, line 111
Class
- SimplenewsCommands
- A Drush commandfile.
Namespace
Drupal\simplenews\CommandsCode
public function spoolSend($limit = FALSE, array $options = [
'pipe' => FALSE,
]) {
if (!simplenews_assert_uri()) {
throw new \Exception('Site URI not specified, use --uri.');
}
if ($limit === FALSE) {
$limit = $this->simplenewsConfig
->get('mail.throttle');
}
elseif ($limit == 0) {
$limit = SpoolStorageInterface::UNLIMITED;
}
$start_time = microtime(TRUE);
$sent = $this->mailer
->sendSpool($limit);
$this->spoolStorage
->clear();
$this->mailer
->updateSendStatus();
$durance = round(microtime(TRUE) - $start_time, 2);
// Report the number of sent mails.
if ($sent > 0) {
$remaining = $this->spoolStorage
->countMails();
if ($options['pipe']) {
// For pipe, print the sent first and then the remaining count,
// separated by a space.
$this
->output()
->writeln($sent . " " . $remaining);
}
else {
$this
->logger()
->log(LogLevel::INFO, dt('Sent @count mails from the queue in @sec seconds.', [
'@count' => $sent,
'@sec' => $durance,
]));
$this
->logger()
->log(LogLevel::INFO, dt('Remaining simplenews mail spool count: @count', [
'@count' => $remaining,
]));
}
}
}