- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_event.php
- Класс: CCalendarEvent
- Вызов: CCalendarEvent::DeleteEmpty
static function DeleteEmpty()
{
global $DB;
if (Util::isSectionStructureConverted())
{
$strSql = 'SELECT CE.ID, CE.LOCATION
FROM b_calendar_event CE
LEFT JOIN b_calendar_section CS ON (CS.ID=CE.SECTION_ID)
WHERE CS.ID is null';
}
else
{
$strSql = 'SELECT CE.ID, CE.LOCATION
FROM b_calendar_event CE
LEFT JOIN b_calendar_event_sect CES ON (CE.ID=CES.EVENT_ID)
WHERE CES.SECT_ID is null';
}
$itemIds = [];
$res = $DB->Query($strSql, false, "FILE: ".__FILE__."
LINE: ".__LINE__);
while($arRes = $res->Fetch())
{
$loc = $arRes['LOCATION'] ?? null;
if ($loc && mb_strlen($loc) > 5 && mb_substr($loc, 0, 5) === 'ECMR_')
{
$loc = RoomsUtil::parseLocation($loc);
if ($loc['mrid'] !== false && $loc['mrevid'] !== false) // Release MR
{
RoomsUtil::releaseLocation($loc);
}
}
else if ($loc && mb_strlen($loc) > 9 && mb_substr($loc, 0, 9) === 'calendar_')
{
$loc = RoomsUtil::parseLocation($loc);
if ($loc['room_id'] !== false && $loc['room_event_id'] !== false) // Release calendar_room
{
RoomsUtil::releaseLocation($loc);
}
}
$itemIds[] = (int)$arRes['ID'];
}
// Clean from 'b_calendar_event'
if (!empty($itemIds))
{
$DB->Query("DELETE FROM b_calendar_event WHERE ID in (".implode(',', $itemIds).")", false,
"FILE: ".__FILE__."
LINE: ".__LINE__);
}
CCalendar::ClearCache(array('section_list', 'event_list'));
}