- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/lib/update/converterobjectcolor.php
- Класс: BitrixCalendarUpdateConverterObjectColor
- Вызов: ConverterObjectColor::execute
public function execute(array &$result)
{
if (Loader::includeModule("calendar")
&& Option::get('calendar', 'needChangeColor', 'Y') === 'N')
{
return self::FINISH_EXECUTION;
}
$status = $this->loadCurrentStatus();
if ($status['finished'])
{
CCalendar::ClearCache(['section_list', 'event_list']);
return self::FINISH_EXECUTION;
}
$newStatus = array(
'count' => $status['count'],
'steps' => $status['steps'],
'sectionFinished' => $status['sectionFinished'],
'finished' => $status['finished']
);
// 1. Update sections
if (!$status['sectionFinished'])
{
$sections = SectionTable::getList([
'filter' => [
'>ID' => $status['sectionLastId'],
],
'limit' => self::PORTION,
'order' => [
'ID' => 'ASC',
]
])->fetchAll();
foreach ($sections as $section)
{
// 1. Replace colors
$color = self::getNewColor($section['COLOR']);
if (strtolower($color) != strtolower($section['COLOR']))
{
CCalendarSect::Edit(array(
'arFields' => array(
'ID' => $section['ID'],
'COLOR' => $color
)
));
}
$newStatus['sectionLastId'] = $section['ID'];
$newStatus['steps']++;
}
if (!empty($newStatus['sectionLastId']))
{
Option::set('calendar', 'changecolor', serialize($newStatus));
return self::CONTINUE_EXECUTION;
}
$newStatus['sectionFinished'] = true;
Option::set('calendar', 'eventindex', serialize($newStatus));
}
// 2. Update events
$events = EventTable::getList([
'filter' => [
'>ID' =>$status['eventLastId'] ?? null,
'DELETED' => 'N',
],
'order' => [
'ID' => 'ASC',
],
'limit' => self::PORTION,
])->fetchAll();
foreach ($events as $event)
{
// 1. Replace colors
$color = self::getNewColor($event['COLOR']);
if (strtolower($color) != strtolower($event['COLOR']))
{
CCalendarEvent::updateColor($event['ID'], $color);
}
$newStatus['eventLastId'] = $event['ID'];
$newStatus['steps']++;
}
if (!empty($newStatus['eventLastId']))
{
Option::set('calendar', 'changecolor', serialize($newStatus));
return self::CONTINUE_EXECUTION;
}
Option::set('calendar', 'needChangeColor', 'N');
Option::delete('calendar', array('name' => 'changecolor'));
return self::FINISH_EXECUTION;
}