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);
106 private function getSerializedNotificationData(Interfaces\
Message $message): ?string
108 $messageBody = $message->getBody();
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 isset($notification[
'eventId'])
126 || isset($notification[
'addresserId'])
127 || isset($notification[
'receiverId'])
128 || isset($notification[
'type'])
129 || isset($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)
149 \CCalendarNotify::Send([
150 'mode' =>
'fail_ical_invite',
151 'eventId' => $parentId,
152 'userId' => $item[
'userId'],
153 'guestId' => $item[
'userId'],
155 'name' => $item[
'name'],
156 'icalMethod' => $item[
'method'],
161 private function getDataForNotify(SenderInvitation $sender): array
163 $event = $sender->getEvent();
165 'email' => $sender->getReceiver()->getEmail(),
166 'eventId' => $event[
'PARENT_ID'],
167 'name' => $event[
'NAME'],
168 'userId' => $event[
'MEETING_HOST'],
169 'method' => $sender->getMethod(),
178 private function setLanguageId(): void
181 if ($site = $siteDb->fetchObject())
194 $serializedData = str_replace(
"'",
"\'", serialize($invitation));
196 ->setBody([
'requestInvitation' => $serializedData])
197 ->setRoutingKey(
'calendar:sending_email_notification')
213 if (!is_iterable($invitations))
215 AddMessage2Log(
'Ical senders collection is not iterable',
'calendar', 4);
219 foreach ($invitations as $invitation)
221 $serializedData = str_replace(
"'",
"\'", serialize($invitation));
223 ->setBody([
'requestInvitation' => $serializedData])
224 ->setRoutingKey(
'calendar:sending_email_notification')
228 (
new Producer())->sendBatch($messages);
static setCurrentLang($language)