3namespace Bitrix\Calendar\Core\Queue\Processor;
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Queue\Interfaces;
7use Bitrix\Calendar\Core\Queue\Message\Message;
8use Bitrix\Calendar\Core\Queue\Producer\Producer;
9use Bitrix\Calendar\ICal\MailInvitation\InvitationInfo;
10use Bitrix\Calendar\ICal\MailInvitation\SenderInvitation;
11use Bitrix\Calendar\Internals\Log\Logger;
12use Bitrix\Main\ArgumentException;
13use Bitrix\Main\LoaderException;
14use Bitrix\Main\Localization\Loc;
15use Bitrix\Main\NotImplementedException;
16use Bitrix\Main\ObjectPropertyException;
17use Bitrix\Main\SiteTable;
18use Bitrix\Main\SystemException;
19use Bitrix\Main\Text\Emoji;
24 private const MAX_ATTEMPTS_INVITATION = 3;
25 private const LOG_MARKER =
'DEBUG_CALENDAR_EMAIL_NOTIFICATION';
31 $this->logger =
new Logger(self::LOG_MARKER);
43 $serializedNotificationData = $this->getSerializedNotificationData(
$message);
44 if (is_null($serializedNotificationData))
51 $notificationData = $this->unserializeNotificationData($serializedNotificationData);
53 catch (TypeError $exception)
55 $this->logger->log($exception);
60 if (!$this->isNotificationFieldsCorrect($notificationData))
62 $this->logger->log($serializedNotificationData);
68 $notificationData[
'eventId'],
69 $notificationData[
'addresserId'],
70 $notificationData[
'receiverId'],
71 $notificationData[
'type'],
72 $notificationData[
'changeFields'] ?? [],
73 $notificationData[
'counterInvitation'] + 1,
76 $notification = $invitation->getSenderInvitation();
77 if (is_null($notification))
79 $this->logger->log($serializedNotificationData);
84 $this->setLanguageId();
85 if ($notification->send())
87 $notification->executeAfterSuccessfulInvitation();
92 if ($notification->getCountAttempsSend() < self::MAX_ATTEMPTS_INVITATION)
100 $failSent[$notification->getEventParentId()] = $this->getDataForNotify($notification);
101 $this->sendFailSendNotify($failSent);
109 if (!is_array($messageBody) || !isset($messageBody[
'requestInvitation']))
114 return $messageBody[
'requestInvitation'];
117 private function isNotificationFieldsCorrect (mixed $notification): bool
119 if (!is_array($notification))
125 $notification[
'eventId'],
126 $notification[
'addresserId'],
127 $notification[
'receiverId'],
128 $notification[
'type'],
129 $notification[
'counterInvitation']
133 private function unserializeNotificationData(
string $serializeNotificationData): mixed
135 $notification = str_replace(
"\'",
"'", $serializeNotificationData);
136 $notification = Emoji::decode($notification);
138 return unserialize($notification, [
'allowed_classes' =>
false]);
141 private function sendFailSendNotify(
array $failSent): void
143 foreach ($failSent as $parentId => $item)
150 \CCalendarNotify::Send([
151 'mode' =>
'fail_ical_invite',
152 'eventId' => $parentId,
153 'userId' => $item[
'userId'],
154 'guestId' => $item[
'userId'],
156 'name' => $item[
'name'],
157 'icalMethod' => $item[
'method'],
162 private function getDataForNotify(SenderInvitation $sender):
array
164 $event = $sender->getEvent();
167 'email' => $sender->getReceiver()->getEmail(),
168 'eventId' =>
$event[
'PARENT_ID'],
170 'userId' =>
$event[
'MEETING_HOST'],
171 'method' => $sender->getMethod(),
180 private function setLanguageId(): void
182 $siteDb = SiteTable::getById(
SITE_ID);
183 if (
$site = $siteDb->fetchObject())
185 Loc::setCurrentLang(
$site->getLanguageId());
196 $serializedData = str_replace(
"'",
"\'", serialize($invitation));
197 $serializedData = Emoji::encode($serializedData);
200 ->setBody([
'requestInvitation' => $serializedData])
201 ->setRoutingKey(
'calendar:sending_email_notification')
217 if (!is_iterable($invitations))
222 foreach ($invitations as $invitation)
224 $serializedData = str_replace(
"'",
"\'", serialize($invitation));
225 $serializedData = Emoji::encode($serializedData);
228 ->setBody([
'requestInvitation' => $serializedData])
229 ->setRoutingKey(
'calendar:sending_email_notification')
static sendMessageToQueue(array $invitation)
process(Interfaces\Message $message)
static sendBatchOfMessagesToQueue(array $invitations)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)