Files
preregister/app/Console/Commands/QueueUnsyncedMailwizzSubscribersCommand.php

47 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Services\DispatchUnsyncedMailwizzSyncJobsService;
use Illuminate\Console\Command;
class QueueUnsyncedMailwizzSubscribersCommand extends Command
{
protected $signature = 'mailwizz:queue-unsynced
{--page= : Limit to a preregistration page ID}
{--dry-run : Only show how many subscribers would be processed}';
protected $description = 'Queue Mailwizz sync jobs for subscribers not yet synced (skips duplicates already queued via unique job lock)';
public function handle(DispatchUnsyncedMailwizzSyncJobsService $dispatcher): int
{
$pageOption = $this->option('page');
$pageId = null;
if ($pageOption !== null && $pageOption !== '') {
if (! is_numeric($pageOption)) {
$this->error(__('The --page option must be a numeric ID.'));
return self::FAILURE;
}
$pageId = (int) $pageOption;
}
$eligible = $dispatcher->eligibleSubscribersQuery()
->when($pageId !== null, fn ($q) => $q->where('preregistration_page_id', $pageId))
->count();
if ($this->option('dry-run')) {
$this->info(__(':count subscriber(s) would be processed.', ['count' => $eligible]));
return self::SUCCESS;
}
$processed = $dispatcher->dispatch($pageId);
$this->info(__('Queued sync for :count subscriber(s). Duplicate jobs for the same subscriber are skipped while one is already pending.', ['count' => $processed]));
return self::SUCCESS;
}
}