RetryPendingSendsCommand   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 1
1
<?php
2
3
namespace Spatie\EmailCampaigns\Commands;
4
5
use Illuminate\Console\Command;
6
use Spatie\EmailCampaigns\Jobs\SendMailJob;
7
use Spatie\EmailCampaigns\Models\CampaignSend;
8
9
class RetryPendingSendsCommand extends Command
10
{
11
    public $signature = 'email-campaigns:retry-pending-sends';
12
13
    public $description = 'Dispatch a job for each MailSend that has not been sent yet';
14
15
    public function handle()
16
    {
17
        $pendingCampaignSendCount = CampaignSend::whereNull('sent_at')->count();
18
19
        $this->comment("Dispatching jobs for {$pendingCampaignSendCount} pending CampaignSends");
20
21
        CampaignSend::whereNull('sent_at')->each(function (CampaignSend $campaignSend) {
22
            dispatch(new SendMailJob($campaignSend));
23
        });
24
25
        $this->comment('All done!');
26
    }
27
}
28