1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sender.php
См. документацию.
1<?php
8
9namespace Bitrix\Sender\Posting;
10
11use Bitrix\Main;
12use Bitrix\Main\Application;
13use Bitrix\Main\Config\Option;
14use Bitrix\Main\DB;
15use Bitrix\Main\Event;
16use Bitrix\Main\Localization\Loc;
17use Bitrix\Main\Type;
18use Bitrix\Sender\Consent\Consent;
19use Bitrix\Sender\ContactTable;
20use Bitrix\Sender\Entity\Campaign;
21use Bitrix\Sender\Entity\Letter;
22use Bitrix\Sender\Integration;
23use Bitrix\Sender\Integration\Bitrix24;
24use Bitrix\Sender\Internals\Model;
25use Bitrix\Sender\Internals\Model\PostingThreadTable;
26use Bitrix\Sender\MailingTable;
27use Bitrix\Sender\Message;
28use Bitrix\Sender\Message\Adapter;
29use Bitrix\Sender\Posting\ThreadStrategy\AbstractThreadStrategy;
30use Bitrix\Sender\Posting\ThreadStrategy\IThreadStrategy;
31use Bitrix\Sender\PostingRecipientTable;
32use Bitrix\Sender\PostingTable;
33use Bitrix\Sender\Recipient;
34use Bitrix\Sender\Runtime\TimeLineJob;
35use Bitrix\Sender\Transport\iLimiter;
36
37Loc::loadMessages(__FILE__);
38
43class Sender
44{
45 const RESULT_NONE = 0;
46 const RESULT_SENT = 1;
47 const RESULT_CONTINUE = 2;
48 const RESULT_ERROR = 3;
49 const RESULT_WAIT = 4;
51
54
56 protected $letter;
58 protected $message;
59
61 protected $timeout;
63 protected $timeAtStart;
64
66 protected $limit;
68 protected $sentCount = 0;
69
71 protected $checkStatusStep = 25;
73 protected $checkStatusCounter = 0;
74
76 protected $isPrevented = false;
77
79 protected $isTrigger = false;
80
82 protected $isReiterate = false;
83
85 protected $mailingId;
87 protected $postingId;
89 protected $letterId;
91 protected $status;
93 protected $sendCount = 0;
95 protected $resultCode = self::RESULT_NONE;
96
101
107 public function __construct(Letter $letter)
108 {
109 $this->letter = $letter;
110 $this->checkStatusStep = (int)Option::get('sender', 'send_check_status_step', $this->checkStatusStep);
111
112 $this->message = $letter->getMessage();
113 $this->message->getConfiguration()->set('LETTER_ID', $this->letter->getId());
114 }
115
123 public function setLimit($limit)
124 {
125 $this->limit = $limit;
126
127 return $this;
128 }
129
137 public function setTimeout($timeout)
138 {
139 $this->timeout = $timeout;
140
141 return $this;
142 }
143
149 public function getResultCode()
150 {
151 return $this->resultCode;
152 }
153
160 public function send()
161 {
162 $this->load($this->letter->get('POSTING_ID'));
163
164 if (!$this->postingId)
165 {
166 $this->resultCode = self::RESULT_ERROR;
167
168 return;
169 }
170
171 if ($this->threadStrategy->isProcessLimited())
172 {
173 $this->resultCode = static::RESULT_CONTINUE;
174 return;
175 }
176
177 $threadState = $this->threadStrategy->checkThreads();
178
179 $this->startTime();
180
181 $this->isConsentSupport = $this->letter
182 ->getMessage()
183 ->getConfiguration()
184 ->get('APPROVE_CONFIRMATION') === 'Y';
185
186 $this->threadStrategy->setPostingId($this->postingId);
187
188 if ($threadState === AbstractThreadStrategy::THREAD_NEEDED)
189 {
190 $this->threadStrategy->fillThreads();
191 }
192
193 $this->threadStrategy->lockThread();
194 $threadId = $this->threadStrategy->getThreadId();
195
196 // lock posting for exclude double parallel sending
197 if (is_null($threadId))
198 {
199 if ($this->letter->get('WAITING_RECIPIENT') === 'Y')
200 {
201 $this->initRecipients();
202 $this->resultCode = static::RESULT_WAITING_RECIPIENT;
203 return;
204 }
205
206 if (!$this->threadStrategy->hasUnprocessedThreads())
207 {
208 // update status of posting
209 $status = self::updateActualStatus(
210 $this->postingId,
211 $this->isPrevented()
212 );
213
214 $this->finalizePosting($status);
215 return;
216 }
217
218 $this->resultCode = static::RESULT_CONTINUE;
219 return;
220 }
221
222 if (static::lock($this->postingId, $threadId) === false)
223 {
224 $this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
225 throw new DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_LOCK'));
226 }
227
228 if ($this->status == PostingTable::STATUS_NEW && $threadId !== 0)
229 {
230 $this->resultCode = static::RESULT_CONTINUE;
231 $this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
232 static::unlock($this->postingId, $threadId);
233 return;
234 }
235
236 // posting not in right status
237 if (!$this->initRecipients())
238 {
239 $this->resultCode = static::RESULT_WAITING_RECIPIENT;
240 $this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
241 static::unlock($this->postingId, $threadId);
242 return;
243 }
244
245 $this->changeStatusToPart();
246
247 // posting competed by status SENT_WITH_ERROR
248 if ($this->status === PostingTable::STATUS_SENT_WITH_ERRORS)
249 {
250 $this->resultCode = static::RESULT_SENT;
251 $this->threadStrategy->updateStatus(PostingThreadTable::STATUS_DONE);
252 static::unlock($this->postingId, $threadId);
253 return;
254 }
255
256 // posting not in right status
257 if ($this->status != PostingTable::STATUS_PART)
258 {
259 $this->resultCode = static::RESULT_ERROR;
260 $this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
261 static::unlock($this->postingId, $threadId);
262 return;
263 }
264
265 if ($this->isTransportLimitsExceeded())
266 {
267 $this->resultCode = static::RESULT_CONTINUE;
268 static::unlock($this->postingId, $threadId);
269
270 return;
271 }
272
273 $threadRecipients = $this->threadStrategy->getRecipients($this->limit);
274 $recipients = static::getRecipientsToSend($threadRecipients);
275 if (($count = count($recipients))> 0)
276 {
277 $this->message->getTransport()->setSendCount($count);
278 if (!$this->message->getTransport()->start())
279 {
280 $this->prevent();
281 }
282 }
283
284 $this->sendToRecipients($recipients);
285
286 $this->message->getTransport()->end();
287
288 // unlock posting for exclude double parallel sending
289 self::unlock($this->postingId, $threadId);
290 // update status of posting
291 $status = self::updateActualStatus(
292 $this->postingId,
293 $this->isPrevented(),
294 $this->threadStrategy->hasUnprocessedThreads()
295 );
296
297 $threadStatus = (
298 $threadRecipients->getSelectedRowsCount() === 0 ?
301 );
302
303 $this->threadStrategy->updateStatus($threadStatus);
304
305 if ($threadId < $this->threadStrategy->lastThreadId())
306 {
307 $this->resultCode = static::RESULT_CONTINUE;
308
309 return;
310 }
311
312 if ($this->threadStrategy->hasUnprocessedThreads())
313 {
314 $this->resultCode = static::RESULT_CONTINUE;
315
316 return;
317 }
318
319 $this->finalizePosting($status);
320 }
321
329 public function load($postingId)
330 {
331 $postingDb = PostingTable::getList(
332 [
333 'select' => [
334 'ID',
335 'STATUS',
336 'MAILING_ID',
337 'MAILING_CHAIN_ID',
338 'MAILING_CHAIN_REITERATE' => 'MAILING_CHAIN.REITERATE',
339 'MAILING_CHAIN_IS_TRIGGER' => 'MAILING_CHAIN.IS_TRIGGER',
340 'COUNT_SEND_ALL'
341 ],
342 'filter' => [
343 '=ID' => $postingId,
344 '=MAILING.ACTIVE' => 'Y',
345 '=MAILING_CHAIN.STATUS' => [
346 Model\LetterTable::STATUS_SEND,
347 Model\LetterTable::STATUS_PLAN,
348 ],
349 ]
350 ]
351 );
352 if ($postingData = $postingDb->fetch())
353 {
354 $this->postingId = $postingData['ID'];
355 $this->status = $postingData['STATUS'];
356
357 $this->mailingId = $postingData['MAILING_ID'];
358 $this->letterId = $postingData['MAILING_CHAIN_ID'];
359 $this->sendCount = $postingData['COUNT_SEND_ALL'];
360
361 $this->isReiterate = $postingData['MAILING_CHAIN_REITERATE'] == 'Y';
362 $this->isTrigger = $postingData['MAILING_CHAIN_IS_TRIGGER'] == 'Y';
363 }
364 }
365
371 public function startTime()
372 {
373 if (!$this->timeout)
374 {
375 return;
376 }
377
378 $this->timeAtStart = microtime(true);
379 @set_time_limit(0);
380 }
381
382 protected function initRecipients(): bool
383 {
384 // if posting in new status, then import recipients from groups
385 // and set right status for sending
386
387 if (!$this->postingId)
388 {
389 return true;
390 }
391
392 if ($this->isTrigger)
393 {
394 return true;
395 }
396
397 if ($this->status !== PostingTable::STATUS_NEW)
398 {
399 return true;
400 }
401
402 return Builder::create()->run($this->postingId);
403 }
404
405 protected function changeStatusToPart()
406 {
407 if (!$this->postingId)
408 {
409 return;
410 }
411
412 if ($this->status == PostingTable::STATUS_PART)
413 {
414 return;
415 }
416
417 if (
418 ($this->status !== PostingTable::STATUS_NEW)
419 && !$this->isTrigger
420 )
421 {
422 return;
423 }
424 $onBeforeStartResult = $this->message->onBeforeStart();
425 if ($onBeforeStartResult->isSuccess())
426 {
427 $this->status = PostingTable::STATUS_PART;
428 Model\PostingTable::update($this->postingId, ['STATUS' => $this->status]);
429 }
430 else
431 {
432 static::updateActualStatus($this->postingId, true);
433 }
434
435 $errorMessage = implode(', ', $onBeforeStartResult->getErrorMessages());
436 if($errorMessage <> '')
437 {
438 Model\LetterTable::update($this->letterId, ['ERROR_MESSAGE' => $errorMessage]);
439 }
440 }
441
450 public static function updateActualStatus($postingId, $isPrevented = false, $awaitThread = false)
451 {
452 //set status and delivered and error emails
453
454 $posting = PostingTable::getList(
455 [
456 'select' => [
457 'ID',
458 'STATUS',
459 'DATE_SENT',
460 'COUNT_SEND_ALL',
461 ],
462 'filter' => ['ID' => $postingId]
463 ]
464 )->fetch();
465
466 $statusesToCheck = [
471 ];
472
473 $weekAgo = (new Type\DateTime())->add('-7 days');
474
475 if ($posting['DATE_SENT'] < $weekAgo)
476 {
478 }
479
481 '@STATUS' => $statusesToCheck,
482 ],
483 );
484 $hasStatusError = array_key_exists(PostingRecipientTable::SEND_RESULT_ERROR, $statusList);
485 $hasStatusNone = array_key_exists(PostingRecipientTable::SEND_RESULT_NONE, $statusList);
486 $hasStatusWait = array_key_exists(PostingRecipientTable::SEND_RESULT_WAIT_ACCEPT, $statusList);
487 if ($isPrevented)
488 {
490 }
491 elseif (!$hasStatusNone && !$awaitThread && !$hasStatusWait)
492 {
494 }
495 else
496 {
498 }
499
500 $postingUpdateFields = [
501 'STATUS' => $status,
502 'DATE_SENT' => $status == PostingTable::STATUS_PART ? null : new Type\DateTime(),
503 'COUNT_SEND_ALL' => 0
504 ];
505
506 $recipientStatusToPostingFieldMap = PostingTable::getRecipientStatusToPostingFieldMap();
507 foreach ($recipientStatusToPostingFieldMap as $recipientStatus => $postingFieldName)
508 {
509 if (!array_key_exists($recipientStatus, $statusList))
510 {
511 $statusList[$recipientStatus] = 0;
512 }
513 $postingUpdateFields[$postingFieldName] = $statusList[$recipientStatus];
514 }
515 $postingUpdateFields['COUNT_SEND_ALL'] = array_sum($statusList);
516 Model\PostingTable::update($postingId, $postingUpdateFields);
517
518 return $status;
519 }
520
529 public static function lock($id, $threadId = 0)
530 {
531 $id = intval($id);
532 $threadId = intval($threadId);
533
534 $lockName = self::getSendpostLockName($id, $threadId);
535
536 return Application::getInstance()->getConnection()->lock($lockName);
537 }
538
547 private static function getSendpostLockName(int $id, int $threadId): string
548 {
549 return "sendpost_{$id}_{$threadId}";
550 }
551
558 {
559 return $this->message->getTransport()->isLimitsExceeded($this->message);
560 }
561
567 public function getExceededLimiter()
568 {
569 return $this->message->getTransport()->getExceededLimiter($this->message);
570 }
571
572 protected function prevent()
573 {
574 return $this->isPrevented = true;
575 }
576
583 private function sendToRecipients($recipients)
584 {
585 $sendResult = null;
586 $dataToInsert = [];
587 try
588 {
589 foreach ($recipients as $recipient)
590 {
591 if ($this->isPrevented() || $this->isStoppedOnRun())
592 {
593 break;
594 }
595
596 $this->setPostingDateSend();
597 $eventData = [];
598 if ($this->canDenySendToRecipient($recipient))
599 {
600 $this->updateRecipientStatus($recipient['ID'],PostingRecipientTable::SEND_RESULT_ERROR);
601 $sendResult = false;
602 $eventData = $this->executeEvent($recipient, $sendResult);
603 }
604 elseif($this->canSendMessageToRecipient($recipient))
605 {
606 $sendResult = $this->sendToRecipient($recipient);
607 if ($this->isPrevented())
608 {
609 break;
610 }
611 $sendResultStatus = ($sendResult ?
614 );
615 $this->updateRecipientStatus($recipient['ID'],$sendResultStatus);
616 $eventData = $this->executeEvent($recipient, $sendResult);
617 }
618 elseif ($this->canSendConsentToRecipient($recipient))
619 {
620 $sendResult = $this->executeConsentToRecipient($recipient);
621 $sendResultStatus = (
622 $sendResult ?
625 );
626 $this->updateRecipientStatus($recipient['ID'],$sendResultStatus);
627 }
628
629 $dataToInsert[] = $eventData;
630
631 if (Bitrix24\Service::isCloud() && $eventData['SEND_RESULT'] && $this->letter->getMessage()->getCode() === Message\iBase::CODE_MAIL)
632 {
633 Bitrix24\Limitation\DailyLimit::increment();
634 }
635 // limit executing script by time
636 if ($this->isTimeout() || $this->isLimitExceeded() || $this->isTransportLimitsExceeded())
637 {
638 break;
639 }
640 // increment sending statistic
641 $this->sentCount++;
642 }
643 } catch(\Exception $e)
644 {}
645
646 try
647 {
648 if($dataToInsert)
649 {
650 Integration\EventHandler::onAfterPostingSendRecipientMultiple(
651 $dataToInsert,
652 $this->letter
653 );
654 }
655 } catch(\Exception $e)
656 {
657
658 }
659
660 return $sendResult;
661 }
662
663 protected function isPrevented()
664 {
665 return $this->isPrevented;
666 }
667
668 protected function isStoppedOnRun()
669 {
670 // check pause or stop status
671 if (++$this->checkStatusCounter < $this->checkStatusStep)
672 {
673 return false;
674 }
675
676 $checkStatusDb = Model\LetterTable::getList(
677 [
678 'select' => ['ID'],
679 'filter' => [
680 '=ID' => $this->letterId,
681 '=STATUS' => Model\LetterTable::STATUS_SEND
682 ]
683 ]
684 );
685 if (!$checkStatusDb->fetch())
686 {
687 return true;
688 }
689
690 $this->checkStatusCounter = 0;
691
692 return false;
693 }
694
695 protected function setPostingDateSend()
696 {
697 if ($this->letter->get('DATE_SEND'))
698 {
699 return;
700 }
701
702 Model\PostingTable::update($this->postingId, ['DATE_SEND' => new Type\DateTime()]);
703 }
704
705 protected function sendToRecipient($recipient)
706 {
707 self::applyRecipientToMessage($this->message, $recipient);
708
709 // event before sending
710 $eventSendParams = [
711 'FIELDS' => $this->message->getFields(),
712 'TRACK_READ' => $this->message->getReadTracker()->getArray(),
713 'TRACK_CLICK' => $this->message->getClickTracker()->getArray(),
714 'MAILING_CHAIN_ID' => $this->letter->getId()
715 ];
716 $linkDomain = $this->message->getReadTracker()->getLinkDomain();
717 if ($linkDomain)
718 {
719 $eventSendParams['LINK_DOMAIN'] = $linkDomain;
720 }
721 $event = new Main\Event('sender', 'OnBeforePostingSendRecipient', [$eventSendParams]);
722 $event->send();
723 foreach ($event->getResults() as $eventResult)
724 {
725 if ($eventResult->getType() == Main\EventResult::ERROR)
726 {
727 return false;
728 }
729
730 if (is_array($eventResult->getParameters()))
731 {
732 $eventSendParams = array_merge($eventSendParams, $eventResult->getParameters());
733 }
734 }
735 if (count($event->getResults()) > 0)
736 {
737 $this->message->setFields($eventSendParams['FIELDS']);
738 $this->message->getReadTracker()->setArray($eventSendParams['TRACK_READ']);
739 $this->message->getReadTracker()->setArray($eventSendParams['TRACK_CLICK']);
740 }
741
742 try
743 {
744 $sendResult = $this->message->send();
745 }
746 catch (Main\Mail\StopException $e)
747 {
748 $sendResult = false;
749 $this->prevent();
750 }
751
752 return $sendResult;
753 }
754
764 public static function applyRecipientToMessage(Adapter $message, array $recipient, $isTest = false)
765 {
767 $message->getReadTracker()->setModuleId('sender')->setFields(['RECIPIENT_ID' => $recipient["ID"]])
768 ->setHandlerUri(Option::get('sender', 'read_link'))->setSiteId($siteId);
769 $message->getClickTracker()->setModuleId('sender')->setFields(['RECIPIENT_ID' => $recipient["ID"]])
770 ->setUriParameters(['bx_sender_conversion_id' => $recipient["ID"]])->setHandlerUri(
771 Option::get('sender', 'click_link')
772 )->setSiteId($siteId);
773 $message->getUnsubTracker()->setModuleId('sender')->setFields(
774 [
775 'RECIPIENT_ID' => $recipient['ID'],
776 'CONTACT_ID' => $recipient['CONTACT_ID'] ?? '',
777 'MAILING_ID' => $recipient['CAMPAIGN_ID'] ?? 0,
778 'EMAIL' => $message->getRecipientCode(),
779 'CODE' => $message->getRecipientCode(),
780 'TEST' => $isTest ? 'Y' : 'N'
781 ]
782 )->setHandlerUri(Option::get('sender', 'unsub_link'))->setSiteId($siteId);
783
784 $fields = self::prepareRecipientFields($recipient);
785 $message->setFields($fields);
786 $message->setRecipientId($recipient['ID']);
787 $message->setRecipientCode($recipient['CONTACT_CODE']);
788 $message->setRecipientType(Recipient\Type::getCode($recipient['CONTACT_TYPE_ID'] ?? ''));
789 $message->setRecipientData($recipient);
790 }
791
792 protected static function prepareRecipientFields($recipient)
793 {
794 // create name from email
795 if (empty($recipient["NAME"]))
796 {
797 $recipient["NAME"] = Recipient\Field::getDefaultName();
798 }
799 $recipient["MAILING_CHAIN_ID"] ??= 0;
800 $senderChainId = (int)$recipient["MAILING_CHAIN_ID"] > 0 ? (int)$recipient["MAILING_CHAIN_ID"]
801 : (int)$recipient['CAMPAIGN_ID'];
802
803 // prepare params for send
804 $fields = [
805 'EMAIL_TO' => $recipient['CONTACT_CODE'] ?? '',
806 'NAME' => $recipient['NAME'] ?? '',
807 'USER_ID' => $recipient["USER_ID"] ?? '',
808 'SENDER_CHAIN_ID' => $senderChainId,
809 'SENDER_CHAIN_CODE' => 'sender_chain_item_'.$senderChainId
810 ];
811
812 if (is_array($recipient['FIELDS']) && count($recipient) > 0)
813 {
814 $fields = $fields + $recipient['FIELDS'];
815 }
816
817 return $fields;
818 }
819
825 public function isTimeout()
826 {
827 if (!$this->timeout)
828 {
829 return false;
830 }
831
832 return (microtime(true) - $this->timeAtStart >= $this->timeout);
833 }
834
840 public function isLimitExceeded()
841 {
842 if (!$this->limit)
843 {
844 return false;
845 }
846
847 return ($this->sentCount > $this->limit);
848 }
849
858 public static function unlock($id, $threadId = 0)
859 {
860 $id = intval($id);
861 $threadId = intval($threadId);
862
863 $lockName = self::getSendpostLockName($id, $threadId);
864
865 return Application::getInstance()->getConnection()->unlock($lockName);
866 }
867
872 {
873 return $this->threadStrategy;
874 }
875
882 {
883 $this->threadStrategy = $threadStrategy;
884 return $this;
885 }
886
890 public function getMessage()
891 : Adapter
892 {
893 return $this->message;
894 }
895 protected function canDenySendToRecipient($recipient) : bool
896 {
897 return (
898 empty($recipient['CONTACT_CODE']) ||
899 $recipient['CONTACT_BLACKLISTED'] === 'Y' ||
900 $recipient['CONTACT_UNSUBSCRIBED'] === 'Y' ||
901 $recipient['CONTACT_MAILING_UNSUBSCRIBED'] === 'Y' ||
903 $recipient['CONTACT_CONSENT_STATUS'],
904 $recipient['CONTACT_CONSENT_REQUEST'],
905 $this->message->getTransport()->getCode()
906 ) &&
907 $this->needConsent()
908 );
909 }
910 protected function canSendConsentToRecipient($recipient) : bool
911 {
912 return (
913 in_array($recipient['CONTACT_CONSENT_STATUS'], [
916 ) &&
918 $recipient['CONTACT_CONSENT_REQUEST'],
919 $this->message->getTransport()->getCode()
920 ) &&
921 $this->needConsent()
922 );
923 }
924 protected function canSendMessageToRecipient($recipient) : bool
925 {
926 return (
927 $recipient['CONTACT_CONSENT_STATUS'] === ContactTable::CONSENT_STATUS_ACCEPT ||
928 !$this->needConsent()
929 );
930 }
931 protected function executeConsentToRecipient($recipient)
932 {
933 $sendResult = null;
934 $sendResult = $this->message->getTransport()->sendConsent(
935 $this->letter->getMessage(), $recipient + ['RECIPIENT_ID' => $recipient['ID'], 'SITE_ID' => SITE_ID]
936 );
937
938 if($sendResult)
939 {
941 $recipient['CONTACT_ID'],
943 );
944
945 if (Bitrix24\Service::isCloud())
946 {
948 }
949 }
950 return $sendResult;
951 }
952
953 protected function executeEvent($recipient, $success)
954 {
955 $eventData = [
956 'SEND_RESULT' => $success,
957 'RECIPIENT' => $recipient,
958 'POSTING' => [
959 'ID' => $this->postingId,
960 'STATUS' => $this->status,
961 'MAILING_ID' => $this->mailingId,
962 'MAILING_CHAIN_ID' => $this->letterId,
963 ]
964 ];
965
966 return $eventData;
967 }
968
969 protected function needConsent(): bool
970 {
971 static $needConsentMessage;
972 if (!isset($needConsentMessage))
973 {
974 $needConsentMessage = $this->isConsentSupport;
975 }
976 return $needConsentMessage;
977 }
978
979 protected function updateRecipientStatus($primary, $status)
980 {
981 Model\Posting\RecipientTable::update(
982 $primary,
983 [
984 'STATUS' => $status,
985 'DATE_SENT' => new Type\DateTime()
986 ]
987 );
988 }
989
991 {
992 return array_filter(iterator_to_array($result),
993 function ($recipient)
994 {
995 return $recipient['STATUS'] === PostingRecipientTable::SEND_RESULT_NONE;
996 });
997 }
998
1004 private function finalizePosting(string $status): void
1005 {
1006 if (!PostingRecipientTable::hasUnprocessed($this->postingId))
1007 {
1008 $onAfterEndResult = $this->message->onAfterEnd();
1009 if (!$onAfterEndResult->isSuccess())
1010 {
1011 $this->resultCode = static::RESULT_CONTINUE;
1012
1013 return;
1014 }
1015 $errorMessage = implode(', ', $onAfterEndResult->getErrorMessages());
1016 if (strlen($errorMessage))
1017 {
1018 Model\LetterTable::update($this->letterId, ['ERROR_MESSAGE' => $errorMessage]);
1019 }
1020 }
1021
1022 // set result code to continue or end of sending
1023 $isContinue = $status == PostingTable::STATUS_PART;
1024 $this->resultCode = $isContinue ? static::RESULT_CONTINUE : static::RESULT_SENT;
1025
1026 if ($this->resultCode == static::RESULT_SENT)
1027 {
1028 $this->resultCode = !$this->threadStrategy->finalize() ? static::RESULT_CONTINUE : static::RESULT_SENT;
1029 TimeLineJob::addEventAgent($this->letterId);
1030 }
1031 }
1032}
$count
Определения admin_tab.php:4
Определения result.php:20
getCode()
Определения error.php:54
Определения event.php:5
static getList(array $parameters=array())
Определения datamanager.php:431
const CONSENT_STATUS_WAIT
Определения contact.php:44
static updateConsentStatus($primary, string $contactStatus)
Определения contact.php:314
const CONSENT_STATUS_NEW
Определения contact.php:45
const CONSENT_STATUS_ACCEPT
Определения contact.php:47
static getDefaultId($siteId=null)
Определения campaign.php:63
static getMailingSiteId($mailingId)
Определения mailing.php:659
static create()
Определения builder.php:75
const RESULT_ERROR
Определения sender.php:48
getExceededLimiter()
Определения sender.php:567
updateRecipientStatus($primary, $status)
Определения sender.php:979
$checkStatusStep
Определения sender.php:71
executeEvent($recipient, $success)
Определения sender.php:953
setThreadStrategy(IThreadStrategy $threadStrategy)
Определения sender.php:881
isTransportLimitsExceeded()
Определения sender.php:557
static prepareRecipientFields($recipient)
Определения sender.php:792
const RESULT_CONTINUE
Определения sender.php:47
canSendMessageToRecipient($recipient)
Определения sender.php:924
setTimeout($timeout)
Определения sender.php:137
getResultCode()
Определения sender.php:149
load($postingId)
Определения sender.php:329
initRecipients()
Определения sender.php:382
static updateActualStatus($postingId, $isPrevented=false, $awaitThread=false)
Определения sender.php:450
const RESULT_WAIT
Определения sender.php:49
isLimitExceeded()
Определения sender.php:840
$isConsentSupport
Определения sender.php:53
needConsent()
Определения sender.php:969
isStoppedOnRun()
Определения sender.php:668
canDenySendToRecipient($recipient)
Определения sender.php:895
executeConsentToRecipient($recipient)
Определения sender.php:931
const RESULT_WAITING_RECIPIENT
Определения sender.php:50
canSendConsentToRecipient($recipient)
Определения sender.php:910
static unlock($id, $threadId=0)
Определения sender.php:858
__construct(Letter $letter)
Определения sender.php:107
getThreadStrategy()
Определения sender.php:871
const RESULT_SENT
Определения sender.php:46
sendToRecipient($recipient)
Определения sender.php:705
changeStatusToPart()
Определения sender.php:405
static applyRecipientToMessage(Adapter $message, array $recipient, $isTest=false)
Определения sender.php:764
isPrevented()
Определения sender.php:663
const RESULT_NONE
Определения sender.php:45
static getRecipientsToSend(\Bitrix\Main\ORM\Query\Result $result)
Определения sender.php:990
static lock($id, $threadId=0)
Определения sender.php:529
setLimit($limit)
Определения sender.php:123
$checkStatusCounter
Определения sender.php:73
setPostingDateSend()
Определения sender.php:695
const SEND_RESULT_DENY
Определения posting.php:674
const SEND_RESULT_WAIT_ACCEPT
Определения posting.php:675
const SEND_RESULT_SUCCESS
Определения posting.php:671
const SEND_RESULT_NONE
Определения posting.php:670
static hasUnprocessed($postingId, $threadId=null)
Определения posting.php:826
const SEND_RESULT_ERROR
Определения posting.php:672
static getRecipientCountByStatus($id, ?array $customFilter=null)
Определения posting.php:252
const STATUS_PART
Определения posting.php:22
const STATUS_NEW
Определения posting.php:21
const STATUS_ABORT
Определения posting.php:25
const STATUS_SENT
Определения posting.php:23
static getRecipientStatusToPostingFieldMap()
Определения posting.php:320
const STATUS_SENT_WITH_ERRORS
Определения posting.php:24
static getDefaultName()
Определения field.php:26
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$success
Определения mail_entry.php:69
$status
Определения session.php:10
$siteId
Определения ajax.php:8
Определения address.php:8
Определения chain.php:3
Определения collection.php:2
Определения agent.php:8
$message
Определения payment.php:8
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if( $guestStatuses !=='') if(!is_array($guestStatuses)) $statusList
Определения options.php:2065
const SITE_ID
Определения sonet_set_content_view.php:12
$fields
Определения yandex_run.php:501