![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/SmsBundle/Broadcast/ |
<?php namespace Mautic\SmsBundle\Broadcast; use Mautic\CampaignBundle\Executioner\ContactFinder\Limiter\ContactLimiter; use Mautic\ChannelBundle\Event\ChannelBroadcastEvent; use Mautic\LeadBundle\Entity\LeadRepository; use Mautic\SmsBundle\Entity\Sms; use Mautic\SmsBundle\Model\SmsModel; use Symfony\Contracts\Translation\TranslatorInterface; class BroadcastExecutioner { private ?ContactLimiter $contactLimiter = null; private ?BroadcastResult $result = null; public function __construct( private SmsModel $smsModel, private BroadcastQuery $broadcastQuery, private TranslatorInterface $translator, private LeadRepository $leadRepository ) { } public function execute(ChannelBroadcastEvent $event): void { // Get list of published broadcasts or broadcast if there is only a single ID $smses = $this->smsModel->getRepository()->getPublishedBroadcastsIterable($event->getId()); foreach ($smses as $sms) { $this->contactLimiter = new ContactLimiter($event->getBatch(), null, $event->getMinContactIdFilter(), $event->getMaxContactIdFilter(), [], $event->getThreadId(), $event->getMaxThreads(), $event->getLimit()); $this->result = new BroadcastResult(); try { $this->send($sms); } catch (\Exception) { } $event->setResults( sprintf('%s: %s', $this->translator->trans('mautic.sms.sms'), $sms->getName()), $this->result->getSentCount(), $this->result->getFailedCount() ); } } /** * @throws LimitQuotaException * @throws \Mautic\CampaignBundle\Executioner\Exception\NoContactsFoundException */ private function send(Sms $sms): void { $contacts = $this->broadcastQuery->getPendingContacts($sms, $this->contactLimiter); while (!empty($contacts)) { $reduction = 0; $leads = []; foreach ($contacts as $contact) { $contactId = $contact['id']; $results = $this->smsModel->sendSms($sms, $contactId, [ 'channel'=> [ 'sms', $sms->getId(), ], 'listId'=> $contact['listId'], ], $leads); $this->result->process($results); $reduction += count($results); } $this->contactLimiter->setBatchMinContactId($contactId + 1); if ($this->contactLimiter->hasCampaignLimit()) { $this->contactLimiter->reduceCampaignLimitRemaining($reduction); } $this->leadRepository->detachEntities($leads); // Next batch $contacts = $this->broadcastQuery->getPendingContacts($sms, $this->contactLimiter); } } }