2023-06-12 13:12:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Maildispatcher\Actions;
|
|
|
|
|
|
|
|
use App\Maildispatcher\Data\MailEntry;
|
|
|
|
use App\Maildispatcher\Models\Maildispatcher;
|
|
|
|
use App\Member\FilterScope;
|
|
|
|
use App\Member\Member;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class ResyncAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
2023-06-15 00:33:13 +02:00
|
|
|
public function handle(): void
|
2023-06-12 13:12:46 +02:00
|
|
|
{
|
|
|
|
foreach (Maildispatcher::get() as $dispatcher) {
|
|
|
|
$dispatcher->gateway->type->sync($dispatcher->name, $dispatcher->gateway->domain, $this->getResults($dispatcher));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-15 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* @return Collection<int, MailEntry>
|
|
|
|
*/
|
2023-06-12 13:12:46 +02:00
|
|
|
public function getResults(Maildispatcher $dispatcher): Collection
|
|
|
|
{
|
2024-01-28 11:42:32 +01:00
|
|
|
return FilterScope::fromPost($dispatcher->filter)->getQuery()->get()
|
2023-10-11 23:13:59 +02:00
|
|
|
->filter(fn ($member) => $member->email || $member->email_parents)
|
|
|
|
->map(fn ($member) => MailEntry::from(['email' => $member->email ?: $member->email_parents]))
|
|
|
|
->unique(fn ($member) => $member->email);
|
2023-06-12 13:12:46 +02:00
|
|
|
}
|
|
|
|
}
|