- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/update/eventhistory/moverelationeventsstepper.php
- Класс: Bitrix\Crm\Update\EventHistory\MoveRelationEventsStepper
- Вызов: MoveRelationEventsStepper::execute
function execute(array &$option)
{
$lastDateCreate = null;
if (isset($option['lastDateCreateTimestamp']) && is_numeric($option['lastDateCreateTimestamp']))
{
$lastDateCreate = DateTime::createFromTimestamp($option['lastDateCreateTimestamp']);
}
$lastId = isset($option['lastId']) ? (int)$option['lastId'] : 0;
$type = self::START_EVENT_TYPE;
if (
isset($option['type'])
&& in_array((int)$option['type'], self::ALL_EVENT_TYPES, true)
)
{
$type = (int)$option['type'];
}
$query = EventTable::query()
->setSelect([
'ID',
'DATE_CREATE',
])
->where('EVENT_TYPE', $type)
->addOrder('DATE_CREATE')
->addOrder('ID')
->setLimit($this->getStepLimit())
;
if ($lastDateCreate instanceof DateTime)
{
$query->where('DATE_CREATE', '>=', $lastDateCreate);
}
if ($lastId > 0)
{
$query->where('ID', '>', $lastId);
}
$processedCount = 0;
foreach ($query->fetchCollection() as $eventCandidate)
{
$lastDateCreate = $eventCandidate->requireDateCreate();
$lastId = $eventCandidate->getId();
$processedCount++;
$this->processRow($eventCandidate);
}
$option['lastDateCreateTimestamp'] = $lastDateCreate ? $lastDateCreate->getTimestamp() : null;
$option['lastId'] = $lastId;
$option['type'] = $type;
if ($processedCount < $this->getStepLimit())
{
if ($type === self::FINISH_EVENT_TYPE)
{
return self::FINISH_EXECUTION;
}
//start processing next type
unset($option['lastDateCreateTimestamp'], $option['lastId']);
$option['type'] = self::FINISH_EVENT_TYPE;
return self::CONTINUE_EXECUTION;
}
return self::CONTINUE_EXECUTION;
}