15 private const DAY_LENGTH = 86400;
26 (
new self())->cleanLocationEvents();
28 return "\\Bitrix\\Calendar\\Rooms\\Util\\CleanLocationEventsAgent::cleanAgent();";
38 private function cleanLocationEvents(): void
40 if (!Loader::includeModule(
'calendar'))
45 $toCleanLocationEvents = $this->getLocationEventsNeededToClean();
47 if ($toCleanLocationEvents)
49 $this->cleanTables($toCleanLocationEvents);
50 \CCalendar::ClearCache([
'event_list']);
59 private function getLocationEventsNeededToClean(): array
61 $toCleanLocationEvents = $this->getEmptyLocationEvents();
64 if (self::DO_CLEAR_DELETED_USER_LOCATION_EVENTS)
66 $toCleanLocationEvents = array_unique(
67 array_merge($toCleanLocationEvents, $this->getDeletedUsersLocationEvents())
71 return array_map(
static function($toCleanLocationEvent){
72 return (
int)$toCleanLocationEvent[
'ID'];
73 }, $toCleanLocationEvents);
80 private function cleanTables($ids)
83 $ids = implode(
',', $ids);
86 DELETE FROM b_calendar_event
87 WHERE ID IN ( " . $ids .
");"
96 private function getEmptyLocationEvents(): array
98 return EventTable::query()
100 ->registerRuntimeField(
104 [
'=this.PARENT_ID' =>
'ref.ID'],
105 [
'join_type' =>
'LEFT']
108 ->where(
'CAL_TYPE',
'location')
109 ->where(
'DELETED',
'N')
113 ->where(
'PARENT.DELETED',
'Y')
114 ->whereNull(
'PARENT.ID')
116 ->where(
'DATE_TO_TS_UTC',
'>', $this->getTimeForQuery())
126 private function getDeletedUsersLocationEvents(): array
128 return EventTable::query()
130 ->registerRuntimeField(
134 [
'=this.CREATED_BY' =>
'ref.ID'],
135 [
'join_type' =>
'INNER']
138 ->where(
'USER.ACTIVE',
'N')
139 ->where(
'CAL_TYPE',
'location')
140 ->where(
'DELETED',
'N')
141 ->where(
'DATE_TO_TS_UTC',
'>', $this->getTimeForQuery())
152 private function getTimeForQuery(): int
154 return time() - self::DAY_LENGTH;