Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventswithentityattendeesfind.php
1<?php
2
4
8
10{
11 const CONVERT_DATA = [
15 ];
16
21 public function process(Interfaces\Message $message): string
22 {
23 $data = $message->getBody();
24
25 if (empty($data['entityType']))
26 {
27 return self::REJECT;
28 }
29
30 $attendeeCode = $this->convertEntityToAttendeeCode($data['entityType'], $data['entityId'] ?? null);
31
32 $events = EventTable::getList([
33 'select' => ['ID'],
34 'filter' => \Bitrix\Main\ORM\Query\Query::filter()
35 ->where('DELETED', 'N')
36 ->whereExpr("%s REGEXP '" . $attendeeCode."(_|$|,)'", ['ATTENDEES_CODES'])
37 ->whereColumn('ID', 'PARENT_ID')
38 //do subtract to make sampling more accurate
39 ->where('DATE_TO_TS_UTC', '>=', time() - \CCalendar::GetDayLen())
40 ,
41 'order' => [
42 'ID' => 'ASC',
43 ],
44 ])->fetchAll();
45
46 if (count($events) === 1)
47 {
48 $this->sendMessageToQueue($events[0]['ID']);
49 }
50 else
51 {
52 $this->sendBatchOfMessagesToQueue($events);
53 }
54
55 return self::ACK;
56 }
57
63 protected function convertEntityToAttendeeCode(string $entityType, int $entityId = null): string
64 {
65 $attendeeCodeType = self::CONVERT_DATA[$entityType] ?? null;
66
67 return $attendeeCodeType ? $attendeeCodeType . ($entityId ?: '') : '';
68 }
69
74 protected function sendMessageToQueue(int $eventId): void
75 {
76 $message = (new \Bitrix\Calendar\Core\Queue\Message\Message())
77 ->setBody([
78 'eventId' => $eventId,
79 ])
80 ->setRoutingKey('calendar:update_event_attendees');
81
82 (new \Bitrix\Calendar\Core\Queue\Producer\Producer())->send($message);
83 }
84
89 protected function sendBatchOfMessagesToQueue(array $events): void
90 {
91 $messages = [];
92
93 foreach ($events as $event)
94 {
95 if (!empty($event['ID']))
96 {
97 $messages[] = (new \Bitrix\Calendar\Core\Queue\Message\Message())
98 ->setBody([
99 'eventId' => $event['ID'],
100 ])
101 ->setRoutingKey('calendar:update_event_attendees')
102 ;
103 }
104 }
105
106 (new \Bitrix\Calendar\Core\Queue\Producer\Producer())->sendBatch($messages);
107 }
108}