41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Lib\Helpers\MailjetHelper;
|
|
use App\Models\BrandContactList;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
|
|
class SyncEmailOptOuts implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$contacts = MailjetHelper::getContactLists();
|
|
|
|
foreach ($contacts as $contact) {
|
|
$listId = $contact['ID'];
|
|
$brandModel = BrandContactList::query()->where('mailjet_list_id', $listId)->with('brand')->first();
|
|
|
|
if ($brandModel) {
|
|
$unsubscribedContacts = MailjetHelper::getUnsubscribedContacts($listId, Carbon::now()->subDay());
|
|
|
|
if (empty($unsubscribedContacts)) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($unsubscribedContacts as $unsubscribedContact) {
|
|
$contact = MailjetHelper::getContact($unsubscribedContact['ContactID']);
|
|
|
|
MailjetHelper::unsubscribeContact($brandModel->brand, $contact[0]["Email"]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|