From 7b92d8f12c521528194f42ec81875ef0bf32e770 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Aug 2017 10:45:09 +0200 Subject: [PATCH] Allow to limit the number of emaisl to be sent Signed-off-by: Joas Schilling --- lib/Command/SendEmails.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Command/SendEmails.php b/lib/Command/SendEmails.php index 4d5bdbe73..b57015e64 100644 --- a/lib/Command/SendEmails.php +++ b/lib/Command/SendEmails.php @@ -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' + ) ; } @@ -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; }