1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cleanlocationeventsagent.php
См. документацию.
1<?php
2
4
6use Bitrix\Main\Entity\ReferenceField;
11
13{
15 private const DAY_LENGTH = 86400;
16 private const FETCH_LIMIT = 100;
17
25 public static function cleanAgent(): string
26 {
27 (new self())->cleanLocationEvents();
28
29 return "\\Bitrix\\Calendar\\Rooms\\Util\\CleanLocationEventsAgent::cleanAgent();";
30 }
31
39 private function cleanLocationEvents(): void
40 {
41 if (!Loader::includeModule('calendar'))
42 {
43 return;
44 }
45
46 $toCleanLocationEvents = $this->getLocationEventsNeededToClean();
47
48 if (!empty($toCleanLocationEvents))
49 {
50 $this->cleanTables($toCleanLocationEvents);
51 \CCalendar::ClearCache(['event_list']);
52 }
53 }
54
60 private function getLocationEventsNeededToClean(): array
61 {
62 $toCleanLocationEvents = $this->getEmptyLocationEvents();
63 //for now, we don't do that because of needing to re-save child events after removing booking
64 //doing that may cause performance problems
65 if (self::DO_CLEAR_DELETED_USER_LOCATION_EVENTS)
66 {
67 $toCleanLocationEvents = array_unique(
68 array_merge($toCleanLocationEvents, $this->getDeletedUsersLocationEvents())
69 );
70 }
71
72 return array_map(static function($toCleanLocationEvent){
73 return (int)$toCleanLocationEvent['ID'];
74 }, $toCleanLocationEvents);
75 }
76
81 private function cleanTables($ids)
82 {
83 global $DB;
84 $ids = implode(',', $ids);
85
86 $DB->Query("
87 DELETE FROM b_calendar_event
88 WHERE ID IN ( " . $ids . ");"
89 );
90 }
91
97 private function getEmptyLocationEvents(): array
98 {
99 return EventTable::query()
100 ->setSelect(['ID'])
101 ->registerRuntimeField(
102 new ReferenceField(
103 'PARENT',
104 EventTable::class,
105 ['=this.PARENT_ID' => 'ref.ID'],
106 ['join_type' => 'LEFT']
107 )
108 )
109 ->where('CAL_TYPE', 'location')
110 ->where('DELETED', 'N')
111 ->where(
112 Query::filter()
113 ->logic('or')
114 ->where('PARENT.DELETED', 'Y')
115 ->whereNull('PARENT.ID')
116 )
117 ->where('DATE_TO_TS_UTC', '>', $this->getTimeForQuery())
118 ->setLimit(self::FETCH_LIMIT)
119 ->exec()->fetchAll()
120 ;
121 }
122
128 private function getDeletedUsersLocationEvents(): array
129 {
130 return EventTable::query()
131 ->setSelect(['ID'])
132 ->registerRuntimeField(
133 new ReferenceField(
134 'USER',
135 UserTable::class,
136 ['=this.CREATED_BY' => 'ref.ID'],
137 ['join_type' => 'INNER']
138 )
139 )
140 ->where('USER.ACTIVE', 'N')
141 ->where('CAL_TYPE', 'location')
142 ->where('DELETED', 'N')
143 ->where('DATE_TO_TS_UTC', '>', $this->getTimeForQuery())
144 ->exec()->fetchAll()
145 ;
146 }
147
154 private function getTimeForQuery(): int
155 {
156 return time() - self::DAY_LENGTH;
157 }
158}
Определения loader.php:13
Определения user.php:48
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $DB
Определения cron_frame.php:29
Определения chain.php:3