mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-30 10:29:42 +00:00
Replace custom ShortMessage usage with Symfony’s SmsMessage.
Switched the entire short message notification system to leverage Symfony's Notifier component and its TexterInterface with SmsMessage. This update simplifies the implementation, removes custom short message handling, and aligns with Symfony's standardized approach.
This commit is contained in:
@@ -21,11 +21,17 @@ namespace Chill\CalendarBundle\Service\ShortMessageNotification;
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Notifier\TexterInterface;
|
||||
|
||||
class BulkCalendarShortMessageSender
|
||||
{
|
||||
public function __construct(private readonly CalendarForShortMessageProvider $provider, private readonly EntityManagerInterface $em, private readonly LoggerInterface $logger, private readonly MessageBusInterface $messageBus, private readonly ShortMessageForCalendarBuilderInterface $messageForCalendarBuilder) {}
|
||||
public function __construct(
|
||||
private readonly CalendarForShortMessageProvider $provider,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly TexterInterface $texter,
|
||||
private readonly ShortMessageForCalendarBuilderInterface $messageForCalendarBuilder,
|
||||
) {}
|
||||
|
||||
public function sendBulkMessageToEligibleCalendars()
|
||||
{
|
||||
@@ -36,7 +42,7 @@ class BulkCalendarShortMessageSender
|
||||
$smses = $this->messageForCalendarBuilder->buildMessageForCalendar($calendar);
|
||||
|
||||
foreach ($smses as $sms) {
|
||||
$this->messageBus->dispatch($sms);
|
||||
$this->texter->send($sms);
|
||||
++$countSms;
|
||||
}
|
||||
|
||||
|
@@ -19,12 +19,26 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessage;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
||||
|
||||
class DefaultShortMessageForCalendarBuilder implements ShortMessageForCalendarBuilderInterface
|
||||
{
|
||||
public function __construct(private readonly \Twig\Environment $engine) {}
|
||||
private readonly PhoneNumberUtil $phoneUtil;
|
||||
|
||||
public function __construct(private readonly \Twig\Environment $engine)
|
||||
{
|
||||
$this->phoneUtil = PhoneNumberUtil::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<SmsMessage>
|
||||
*
|
||||
* @throws \Twig\Error\LoaderError
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
*/
|
||||
public function buildMessageForCalendar(Calendar $calendar): array
|
||||
{
|
||||
if (true !== $calendar->getSendSMS()) {
|
||||
@@ -39,16 +53,14 @@ class DefaultShortMessageForCalendarBuilder implements ShortMessageForCalendarBu
|
||||
}
|
||||
|
||||
if (Calendar::SMS_PENDING === $calendar->getSmsStatus()) {
|
||||
$toUsers[] = new ShortMessage(
|
||||
$toUsers[] = new SmsMessage(
|
||||
$this->phoneUtil->format($person->getMobilenumber(), PhoneNumberFormat::E164),
|
||||
$this->engine->render('@ChillCalendar/CalendarShortMessage/short_message.txt.twig', ['calendar' => $calendar]),
|
||||
$person->getMobilenumber(),
|
||||
ShortMessage::PRIORITY_LOW
|
||||
);
|
||||
} elseif (Calendar::SMS_CANCEL_PENDING === $calendar->getSmsStatus()) {
|
||||
$toUsers[] = new ShortMessage(
|
||||
$toUsers[] = new SmsMessage(
|
||||
$this->phoneUtil->format($person->getMobilenumber(), PhoneNumberFormat::E164),
|
||||
$this->engine->render('@ChillCalendar/CalendarShortMessage/short_message_canceled.txt.twig', ['calendar' => $calendar]),
|
||||
$person->getMobilenumber(),
|
||||
ShortMessage::PRIORITY_LOW
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -19,12 +19,12 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessage;
|
||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
||||
|
||||
interface ShortMessageForCalendarBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @return array|ShortMessage[]
|
||||
* @return list<SmsMessage>
|
||||
*/
|
||||
public function buildMessageForCalendar(Calendar $calendar): array;
|
||||
}
|
||||
|
Reference in New Issue
Block a user