Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailinvitationmanager.php
1<?php
2
3
5
6
13use CAgent;
14use CCalendarNotify;
15
24{
25 private const MAX_ATTEMPS_INVITATION = 3;
26
27
32 public static function manageSendingInvitation($serializedSenders): void
33 {
34 $serializedSenders = str_replace("\'", "'", $serializedSenders);
35 $serializedSenders = \Bitrix\Main\Text\Emoji::decode($serializedSenders);
36 $sendersCollection = self::unserializeMailSendersBatch($serializedSenders);
37
38 if (!is_iterable($sendersCollection))
39 {
40 AddMessage2Log('Ical senders collection is not iterable', 'calendar', 4);
41 }
42 else
43 {
44 $unsuccessfulSent = [];
45 $failSent = [];
46 foreach ($sendersCollection as $sender)
47 {
48 if ($sender instanceof SenderInvitation)
49 {
50 self::setLanguageId();
51 $sender->incrementCounterInvitations();
52 $currentSender = clone $sender;
53
54 if ($sender->send())
55 {
56 $sender->executeAfterSuccessfulInvitation();
57 }
58 elseif ($sender->getCountAttempsSend() < self::MAX_ATTEMPS_INVITATION)
59 {
60 $unsuccessfulSent[] = $currentSender;
61 }
62 else
63 {
64 $failSent[$sender->getEventParentId()] = self::getDataForNotify($sender);
65 }
66 }
67 }
68
69 if (!empty($unsuccessfulSent))
70 {
71 self::createAgentSent($unsuccessfulSent);
72 }
73
74 if (!empty($failSent))
75 {
76 self::sentFailSentNotify($failSent);
77 }
78 }
79 }
80
85 private static function getDataForNotify(SenderInvitation $sender): array
86 {
87 $event = $sender->getEvent();
88 return [
89 'email' => $sender->getReceiver()->getEmail(),
90 'eventId' => $event['PARENT_ID'],
91 'name' => $event['NAME'],
92 'userId' => $event['MEETING_HOST'],
93 'method' => $sender->getMethod(),
94 ];
95 }
96
100 public static function createAgentSent(array $sendersCollection): void
101 {
102 // TODO: it's better to avoid serialized data in the agent parameters, maybe use QueueManager here
103 $serializedData = str_replace("'", "\'", serialize($sendersCollection));
104 $agentName = "\\Bitrix\\Calendar\\ICal\\MailInvitation\\MailInvitationManager::manageSendingInvitation('"
105 . $serializedData
106 . "');";
107 $agentName = \Bitrix\Main\Text\Emoji::encode($agentName);
108
109 // Workaround to avoid deserialization bug like mantis#162578
110 // We need length in bytes not in symbols
111 if (strlen($agentName) < 65000)
112 {
113 CAgent::addAgent(
114 $agentName,
115 "calendar",
116 "N",
117 0,
118 "",
119 "Y",
120 ""
121 );
122 }
123 }
124
128 private static function sentFailSentNotify(array $failSent): void
129 {
130 foreach ($failSent as $parentId => $item)
131 {
132 if (isset($item[0]))
133 {
134 $item = $item[0];
135 }
136 CCalendarNotify::Send([
137 'mode' => 'fail_ical_invite',
138 'eventId' => $parentId,
139 'userId' => $item['userId'],
140 'guestId' => $item['userId'],
141 'items' => $item,
142 'name' => $item['name'],
143 'icalMethod' => $item['method'],
144 ]);
145 }
146 }
147
152 private static function unserializeMailSendersBatch(string $serializedSenders)
153 {
154 return unserialize($serializedSenders, ['allowed_classes' => [
155 AttachCollection::class,
156 Attach::class,
157 AttendeesCollection::class,
158 MailAddresser::class,
159 MailReceiver::class,
160 Attendee::class,
161 SenderRequestInvitation::class,
162 SenderEditInvitation::class,
163 SenderCancelInvitation::class,
164 Context::class
165 ]]);
166 }
167
173 private static function setLanguageId(): void
174 {
175 $siteDb = \Bitrix\Main\SiteTable::getById(SITE_ID);
176 if ($site = $siteDb->fetchObject())
177 {
178 Loc::setCurrentLang($site->getLanguageId());
179 }
180 }
181}
static setCurrentLang($language)
Definition loc.php:95