Publication initiale de RelaisSMS : documentation et sources nettoyees
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\SmsCampaign;
|
||||
use App\Services\Sms\SmsCampaignSender;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SendDueSmsCampaignsCommand extends Command
|
||||
{
|
||||
protected $signature = 'sms-campaigns:send-due {--limit=50 : Nombre maximum de campagnes a prendre en charge.}';
|
||||
|
||||
protected $description = 'Envoie les campagnes SMS programmees arrivees a echeance.';
|
||||
|
||||
public function handle(SmsCampaignSender $sender): int
|
||||
{
|
||||
$limit = max(1, (int) $this->option('limit'));
|
||||
$processed = 0;
|
||||
|
||||
SmsCampaign::query()
|
||||
->where('status', 'scheduled')
|
||||
->whereNotNull('scheduled_at')
|
||||
->where('scheduled_at', '<=', now())
|
||||
->orderBy('scheduled_at')
|
||||
->limit($limit)
|
||||
->get()
|
||||
->each(function (SmsCampaign $campaign) use ($sender, &$processed): void {
|
||||
if ($sender->sendScheduled($campaign) !== null) {
|
||||
$processed++;
|
||||
}
|
||||
});
|
||||
|
||||
$this->line($processed.' campagne(s) SMS programmee(s) prise(s) en charge.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user