23 return get_called_class();
29 $sqlHelper = $connection->getSqlHelper();
30 if (Loader::includeModule(
"calendar")
31 && (Option::get(
'calendar',
'eventWithLocationConverted',
'N') ===
'Y')
34 Rooms\Manager::createInstance()->clearCache();
37 $status = $this->loadCurrentStatus();
40 'count' => $status[
'count'],
41 'steps' => $status[
'steps'],
42 'newFinished' => $status[
'newFinished'],
43 'lastEventId' => $status[
'lastEventId']
47 if (!$status[
'newFinished'])
49 $res = $this->getLocationEvent($newStatus[
'lastEventId']);
50 while ($event = $res->Fetch())
52 $eventId = (int)$event[
'ID'];
53 $newStatus[
'lastEventId'] = $eventId;
55 $parentRes = $this->getLocationParentEvent($eventId);
56 if ($parentEvent = $parentRes->Fetch())
58 $ownerName = $sqlHelper->forSql(CCalendar::GetUserName($parentEvent[
'CREATED_BY']));
59 $parentId = (int)$parentEvent[
'ID'];
60 $this->updateLocationEvent($parentId, $ownerName, $eventId);
64 $this->deleteEvent($eventId);
67 $newStatus[
'steps']++;
70 if (isset($newStatus[
'lastEventId']) && $res->SelectedRowsCount() !== 0)
72 Option::set(
'calendar',
'eventWithLocationConvertedStatus', serialize($newStatus));
75 'count' => $newStatus[
'count'],
76 'steps' => $newStatus[
'steps'],
77 'lastEventId' => $newStatus[
'lastEventId'],
78 'newFinished' => $newStatus[
'newFinished']
84 $newStatus[
'newFinished'] =
true;
85 $newStatus[
'lastEventId'] = PHP_INT_MAX;
89 $meetingRoomArray = $this->getMeetingRoomArray();
91 if ($meetingRoomArray !==
null)
93 $res = $this->getIBlockEvent($newStatus[
'lastEventId']);
94 while ($event = $res->Fetch())
96 $eventId = (int)$event[
'ID'];
97 $newStatus[
'lastEventId'] = $eventId;
98 $phrases = $this->prepareLocationEvent($event, $meetingRoomArray);
100 if ($phrases !==
null && isset($phrases[
'child']) && isset($phrases[
'parent']))
102 $this->updateLocationValue($phrases[
'parent'], $eventId);
103 if ($event[
'IS_MEETING'])
105 $this->updateLocationValueForChildEvents($phrases[
'child'], $eventId);
107 Rooms\Manager::setEventIdForLocation($eventId);
110 $newStatus[
'steps']++;
113 if (isset($newStatus[
'lastEventId']) && $res->SelectedRowsCount() !== 0)
115 Option::set(
'calendar',
'eventWithLocationConvertedStatus', serialize($newStatus));
118 'count' => $newStatus[
'count'],
119 'steps' => $newStatus[
'steps'],
120 'lastEventId' => $newStatus[
'lastEventId'],
121 'newFinished' => $newStatus[
'newFinished']
128 Option::set(
'calendar',
'eventWithLocationConverted',
'Y');
129 Option::delete(
'calendar', [
'name' =>
'eventWithLocationConvertedStatus']);
130 Rooms\Manager::createInstance()->clearCache();
138 private function loadCurrentStatus()
140 $status = Option::get(
'calendar',
'eventWithLocationConvertedStatus',
'default');
141 $status = ($status !==
'default' ? @unserialize($status, [
'allowed_classes' =>
false]) : []);
142 $status = (is_array($status) ? $status : []);
147 'count' => $this->getTotalCount(),
149 'lastEventId' => PHP_INT_MAX,
150 'newFinished' => false
160 private function getTotalCount(): int
162 return $this->getTotalCountLocation() + $this->getTotalCountIBlock();
168 private function getTotalCountLocation(): int
172 $result = $DB->Query(
"
173 SELECT COUNT(*) AS cnt
174 FROM b_calendar_event
176 AND CAL_TYPE = 'location'
179 if ($res = $result->Fetch())
181 $count = (int)$res[
'cnt'];
190 private function getTotalCountIBlock(): int
195 $result = $DB->Query(
"
196 SELECT COUNT(*) AS cnt
197 FROM b_calendar_event
199 AND DATE_TO_TS_UTC > " . $timestamp .
"
201 AND LOCATION LIKE 'ECMR%'"
203 if ($res = $result->Fetch())
205 $count = (int)$res[
'cnt'];
214 private function getLocationEvent(
int $lastEventId)
218 SELECT ID, PARENT_ID, CAL_TYPE
219 FROM b_calendar_event
221 AND CAL_TYPE = 'location'
223 AND ID < ".$lastEventId.
"
225 LIMIT ".self::PORTION.
";"
233 private function getLocationParentEvent(
int $eventId)
237 SELECT ID, CREATED_BY, LOCATION
238 FROM b_calendar_event
239 WHERE LOCATION LIKE 'calendar_%_".$eventId.
"'
251 private function updateLocationEvent(
int $parentId,
string $ownerName,
int $eventId): void
255 UPDATE b_calendar_event
256 SET PARENT_ID = " . $parentId .
", NAME = '" . $ownerName .
"'
257 WHERE ID = " . $eventId .
";"
264 private function getMeetingRoomArray()
266 $newMeetingRooms = Option::get(
'calendar',
'converted_meeting_rooms');
267 $newMeetingRooms = json_decode($newMeetingRooms,
true);
269 if (!empty($newMeetingRooms) && is_array($newMeetingRooms))
271 return $newMeetingRooms;
280 private function getIBlockEvent(
int $lastEventId)
286 SELECT ID, PARENT_ID, DATE_FROM,
287 DATE_TO, TZ_FROM, TZ_TO, IS_MEETING,
288 RRULE, EXDATE, CREATED_BY, DT_SKIP_TIME
289 FROM b_calendar_event
291 AND DATE_TO_TS_UTC > " . $timestamp .
"
292 AND LOCATION LIKE 'ECMR%'
294 AND ID < ".$lastEventId.
"
296 LIMIT " . self::PORTION .
";"
305 private function prepareLocationEvent($event, $meetingRoomArray): ?array
308 $id = (int)$event[
'ID'];
309 $dateToRaw = strtotime($event[
'DATE_TO']);
310 $dateFromRaw = strtotime($event[
'DATE_FROM']);
311 $dateTo = CCalendar::Date($dateToRaw);
312 $dateFrom = CCalendar::Date($dateFromRaw);
314 $RRule = CCalendarEvent::ParseRRULE($event[
'RRULE']);
315 if (isset($RRule[
'~UNTIL']))
317 unset($RRule[
'~UNTIL']);
319 if ($RRule[
'FREQ'] ===
'WEEKLY' && !isset($RRule[
'BYDAY']))
324 $skipTime = $event[
'DT_SKIP_TIME'] ===
'Y';
326 $phraseLocationParent =
'calendar_#ROOMID#_#EVENTID#';
327 $phraseLocationChild =
'calendar_#ROOMID#';
332 FROM b_calendar_event
333 WHERE ID = " . $id .
";"
335 if ($location = $res->Fetch())
337 $location = explode(
"_", $location[
'LOCATION']);
338 $mrId = $location[1];
339 $roomId = $meetingRoomArray[$mrId];
341 $locationEventId = Rooms\Manager::reserveRoom([
344 'DATE_FROM' => $dateFrom,
345 'DATE_TO' => $dateTo,
346 'TZ_FROM' => $event[
'TZ_FROM'],
347 'TZ_TO' => $event[
'TZ_TO'],
348 'SKIP_TIME' => $skipTime,
350 'EXDATE' => $event[
'EXDATE'],
351 'CREATED_BY' => (
int)$event[
'CREATED_BY']
353 'userId' => (
int)$event[
'CREATED_BY']
355 'room_event_id' =>
false,
356 'room_id' => (
int)$roomId
359 if ($locationEventId && $roomId)
361 $result[
'parent'] = str_replace(
362 [
'#ROOMID#',
'#EVENTID#'],
363 [$roomId, $locationEventId],
364 $phraseLocationParent
366 $result[
'child'] = str_replace(
382 private function updateLocationValue(
string $phraseLocation,
int $id) : void
386 UPDATE b_calendar_event
387 SET LOCATION = '" . $phraseLocation .
"'
396 private function updateLocationValueForChildEvents(
string $phraseLocation,
int $id) : void
400 UPDATE b_calendar_event
401 SET LOCATION = '" . $phraseLocation .
"'
402 WHERE PARENT_ID = " . $id.
"
404 AND CAL_TYPE <> 'location'
412 private function deleteEvent(
int $id)
416 UPDATE b_calendar_event
418 WHERE ID = " . $id .
";"
static getConnection($name="")
static getMessage($code, $replace=null, $language=null)