feat: Phase 4 - Mailwizz integration with subscriber sync and retry

This commit is contained in:
2026-04-03 22:03:53 +02:00
parent a1d570254e
commit 83e2158383
13 changed files with 983 additions and 133 deletions

View File

@@ -0,0 +1,46 @@
<?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;
}
}