Skip to content

Commit

Permalink
Merge pull request #180 from nextcloud/issue-179-option-to-limit-numb…
Browse files Browse the repository at this point in the history
…er-of-emails

Allow to limit the number of emaisl to be sent
  • Loading branch information
nickvergessen authored Aug 2, 2017
2 parents 309f6ae + 7b92d8f commit 0505686
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/Command/SendEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ protected function configure() {
'Only sends the emails for users which have configured the mails: "hourly", "daily" or "weekly"',
'all'
)
->addOption(
'limit',
'l',
InputOption::VALUE_REQUIRED,
'Only sends this amount of emails to give the email server some time to relax',
'unlimited'
)
;
}

Expand All @@ -94,11 +101,15 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$restrictEmails = null;
}

do {
// If we are in CLI mode, we keep sending emails
// until we are done.
$emails_sent = $this->queueHandler->sendEmails(MailQueueHandler::CLI_EMAIL_BATCH_SIZE, $sendTime, true, $restrictEmails);
} while ($emails_sent === MailQueueHandler::CLI_EMAIL_BATCH_SIZE);
$limit = $input->getOption('limit');

if ($limit === 'unlimited') {
do {
$emails_sent = $this->queueHandler->sendEmails(MailQueueHandler::CLI_EMAIL_BATCH_SIZE, $sendTime, true, $restrictEmails);
} while ($emails_sent === MailQueueHandler::CLI_EMAIL_BATCH_SIZE);
} else {
$this->queueHandler->sendEmails($limit, $sendTime, true, $restrictEmails);
}

return 0;
}
Expand Down

0 comments on commit 0505686

Please sign in to comment.