Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
eventswithentityattendeesfind.php
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Queue\Processor
;
4
5
use
Bitrix\Calendar\Core\Queue\Interfaces
;
6
use
Bitrix\Calendar\Internals\EventTable
;
7
use
Bitrix\Calendar\Watcher\Membership\Handler\Handler
;
8
9
class
EventsWithEntityAttendeesFind
implements
Interfaces\Processor
10
{
11
const
CONVERT_DATA
= [
12
Handler::WORK_GROUP_TYPE
=>
'SG'
,
13
Handler::DEPARTMENT_TYPE
=>
'DR'
,
14
Handler::ALL_USERS_TYPE
=>
'UA'
,
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
}
Bitrix\Calendar\Core\Queue\Processor\EventsWithEntityAttendeesFind
Definition
eventswithentityattendeesfind.php:10
Bitrix\Calendar\Core\Queue\Processor\EventsWithEntityAttendeesFind\sendBatchOfMessagesToQueue
sendBatchOfMessagesToQueue(array $events)
Definition
eventswithentityattendeesfind.php:89
Bitrix\Calendar\Core\Queue\Processor\EventsWithEntityAttendeesFind\process
process(Interfaces\Message $message)
Definition
eventswithentityattendeesfind.php:21
Bitrix\Calendar\Core\Queue\Processor\EventsWithEntityAttendeesFind\CONVERT_DATA
const CONVERT_DATA
Definition
eventswithentityattendeesfind.php:11
Bitrix\Calendar\Core\Queue\Processor\EventsWithEntityAttendeesFind\sendMessageToQueue
sendMessageToQueue(int $eventId)
Definition
eventswithentityattendeesfind.php:74
Bitrix\Calendar\Core\Queue\Processor\EventsWithEntityAttendeesFind\convertEntityToAttendeeCode
convertEntityToAttendeeCode(string $entityType, int $entityId=null)
Definition
eventswithentityattendeesfind.php:63
Bitrix\Calendar\Internals\EventTable
Definition
event.php:27
Bitrix\Calendar\Watcher\Membership\Handler\Handler
Definition
handler.php:6
Bitrix\Calendar\Watcher\Membership\Handler\Handler\WORK_GROUP_TYPE
const WORK_GROUP_TYPE
Definition
handler.php:7
Bitrix\Calendar\Watcher\Membership\Handler\Handler\DEPARTMENT_TYPE
const DEPARTMENT_TYPE
Definition
handler.php:8
Bitrix\Calendar\Watcher\Membership\Handler\Handler\ALL_USERS_TYPE
const ALL_USERS_TYPE
Definition
handler.php:9
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Calendar\Core\Queue\Interfaces\Message
Definition
message.php:16
Bitrix\Calendar\Core\Queue\Interfaces\Processor
Definition
processor.php:5
Bitrix\Calendar\Core\Queue\Interfaces\Processor\REJECT
const REJECT
Definition
processor.php:15
Bitrix\Calendar\Core\Queue\Interfaces\Processor\ACK
const ACK
Definition
processor.php:9
Bitrix\Calendar\Core\Queue\Interfaces
Definition
consumer.php:3
Bitrix\Calendar\Core\Queue\Processor
Definition
eventattendeesupdate.php:3
Bitrix
modules
calendar
lib
core
queue
processor
eventswithentityattendeesfind.php
Создано системой
1.10.0