1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mailinvitationmanager.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\ICal\MailInvitation;
5
6
7use Bitrix\Calendar\ICal\Builder\Attach;
8use Bitrix\Calendar\ICal\Builder\Attendee;
9use Bitrix\Calendar\ICal\Builder\AttendeesCollection;
10use Bitrix\Calendar\ICal\Builder\AttachCollection;
11use Bitrix\Main\LoaderException;
12use Bitrix\Main\Localization\Loc;
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 return;
41 }
42
43 $unsuccessfulSent = [];
44 $failSent = [];
45 foreach ($sendersCollection as $sender)
46 {
47 if ($sender instanceof SenderInvitation)
48 {
49 self::setLanguageId();
50 $sender->incrementCounterInvitations();
51 $currentSender = clone $sender;
52
53 if ($sender->send())
54 {
55 $sender->executeAfterSuccessfulInvitation();
56 }
57 elseif ($sender->getCountAttempsSend() < self::MAX_ATTEMPS_INVITATION)
58 {
59 $unsuccessfulSent[] = $currentSender;
60 }
61 else
62 {
63 $failSent[$sender->getEventParentId()] = self::getDataForNotify($sender);
64 }
65 }
66 }
67
68 if (!empty($unsuccessfulSent))
69 {
70 self::createAgentSent($unsuccessfulSent);
71 }
72
73 if (!empty($failSent))
74 {
75 self::sentFailSentNotify($failSent);
76 }
77 }
78
83 private static function getDataForNotify(SenderInvitation $sender): array
84 {
85 $event = $sender->getEvent();
86 return [
87 'email' => $sender->getReceiver()->getEmail(),
88 'eventId' => $event['PARENT_ID'],
89 'name' => $event['NAME'],
90 'userId' => $event['MEETING_HOST'],
91 'method' => $sender->getMethod(),
92 ];
93 }
94
98 public static function createAgentSent(array $sendersCollection): void
99 {
100 // TODO: it's better to avoid serialized data in the agent parameters, maybe use QueueManager here
101 $serializedData = str_replace("'", "\'", serialize($sendersCollection));
102 $agentName = "\\Bitrix\\Calendar\\ICal\\MailInvitation\\MailInvitationManager::manageSendingInvitation('"
103 . $serializedData
104 . "');";
105 $agentName = \Bitrix\Main\Text\Emoji::encode($agentName);
106
107 // Workaround to avoid deserialization bug like mantis#162578
108 // We need length in bytes not in symbols
109 if (strlen($agentName) < 65000)
110 {
111 CAgent::addAgent(
112 $agentName,
113 "calendar",
114 "N",
115 0,
116 "",
117 "Y",
118 ""
119 );
120 }
121 }
122
126 private static function sentFailSentNotify(array $failSent): void
127 {
128 foreach ($failSent as $parentId => $item)
129 {
130 if (isset($item[0]))
131 {
132 $item = $item[0];
133 }
134 CCalendarNotify::Send([
135 'mode' => 'fail_ical_invite',
136 'eventId' => $parentId,
137 'userId' => $item['userId'],
138 'guestId' => $item['userId'],
139 'items' => $item,
140 'name' => $item['name'],
141 'icalMethod' => $item['method'],
142 ]);
143 }
144 }
145
150 private static function unserializeMailSendersBatch(string $serializedSenders)
151 {
152 return unserialize($serializedSenders, ['allowed_classes' => [
153 AttachCollection::class,
154 Attach::class,
155 AttendeesCollection::class,
156 MailAddresser::class,
157 MailReceiver::class,
158 Attendee::class,
159 SenderRequestInvitation::class,
160 SenderEditInvitation::class,
161 SenderCancelInvitation::class,
162 Context::class
163 ]]);
164 }
165
171 private static function setLanguageId(): void
172 {
174 if ($site = $siteDb->fetchObject())
175 {
176 Loc::setCurrentLang($site->getLanguageId());
177 }
178 }
179}
static createAgentSent(array $sendersCollection)
Определения mailinvitationmanager.php:98
static manageSendingInvitation($serializedSenders)
Определения mailinvitationmanager.php:32
static getById($id)
Определения datamanager.php:364
static encode($text)
Определения emoji.php:17
static decode($text)
Определения emoji.php:24
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
const SITE_ID
Определения sonet_set_content_view.php:12
$site
Определения yandex_run.php:614