-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95122b8
commit 62d98a7
Showing
11 changed files
with
133 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\Mailing\Commands\Handlers; | ||
|
||
use App\Mailing\SrsMail; | ||
use App\Mailing\SrsMailData; | ||
use App\Model\Mailing\Commands\SendMails; | ||
use App\Model\Mailing\Recipient; | ||
use App\Model\Mailing\Repositories\MailQueueRepository; | ||
use App\Model\Settings\Queries\SettingStringValueQuery; | ||
use App\Model\Settings\Settings; | ||
use App\Services\QueryBus; | ||
use DateTimeImmutable; | ||
use Ublaboo\Mailing\MailFactory; | ||
|
||
class SendMailsHandler | ||
{ | ||
public function __construct( | ||
private readonly QueryBus $queryBus, | ||
private readonly MailQueueRepository $mailQueueRepository, | ||
private readonly MailFactory $mailFactory, | ||
) { | ||
} | ||
|
||
public function __invoke(SendMails $command): void | ||
{ | ||
$mailsToSend = $this->mailQueueRepository->findMailsToSend(50); | ||
|
||
if ($mailsToSend->isEmpty()) { | ||
return; | ||
} | ||
|
||
$from = new Recipient( | ||
$this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_EMAIL)), | ||
$this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)), | ||
); | ||
|
||
foreach ($mailsToSend as $mailToSend) { | ||
$to = new Recipient($mailToSend->getRecipientEmail(), $mailToSend->getRecipientName()); | ||
$messageData = new SrsMailData($from, $to, $mailToSend->getMail()->getSubject(), $mailToSend->getMail()->getText()); | ||
$mail = $this->mailFactory->createByType(SrsMail::class, $messageData); | ||
$mail->send(); | ||
|
||
$mailToSend->setSent(true); | ||
$mailToSend->setSendDatetime(new DateTimeImmutable()); | ||
$this->mailQueueRepository->save($mailToSend); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\Mailing\Commands; | ||
|
||
class SendMails | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.