From 55cc0cba0e0f8de48aa28781299a953165e07956 Mon Sep 17 00:00:00 2001 From: Peter Dulacka Date: Thu, 12 Sep 2024 13:01:51 +0200 Subject: [PATCH] Fix newsletters marked as finished Beam marked newsletters as finished also if they were scheduled to be sent in the future. It was enough that they weren't sent "now" and they were marked as finished. remp/respekt#289 --- .../Commands/SendNewslettersCommand.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Console/Commands/SendNewslettersCommand.php b/src/Console/Commands/SendNewslettersCommand.php index 2288489..8336e2f 100644 --- a/src/Console/Commands/SendNewslettersCommand.php +++ b/src/Console/Commands/SendNewslettersCommand.php @@ -35,9 +35,7 @@ public function __construct(MailerContract $mailer) public function handle() { - $this->line(''); - $this->line('***** Sending newsletters *****'); - $this->line(''); + $this->line(Carbon::now() . ': Processing newsletters'); $newsletters = Newsletter::where('state', Newsletter::STATE_STARTED) ->where('starts_at', '<=', Carbon::now()) @@ -49,6 +47,7 @@ public function handle() } foreach ($newsletters as $newsletter) { + $this->line(Carbon::now() . ": * {$newsletter->name}"); $nextSending = $newsletter->starts_at; $hasMore = false; @@ -57,26 +56,23 @@ public function handle() } if ($nextSending) { - if ($nextSending->gt(Carbon::now())) { - // Not sending, date is in future - continue; - } - - $this->line(sprintf("Processing newsletter: %s", $newsletter->name)); + $this->line(Carbon::now() . ": * sending"); $this->sendNewsletter($newsletter); + $this->line(Carbon::now() . ": * sent"); $newsletter->last_sent_at = Carbon::now(); if (!$hasMore) { $newsletter->state = Newsletter::STATE_FINISHED; } - } else { + } elseif (!$hasMore) { + $this->line(Carbon::now() . ": * marking as finished"); $newsletter->state = Newsletter::STATE_FINISHED; } $newsletter->save(); } - $this->line('Done!'); + $this->line(Carbon::now() . ': Done!'); return 0; }