- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/lib/api/event.php
- Класс: BitrixRestApiEvent
- Вызов: Event::eventOfflineGet
static function eventOfflineGet($query, $n, CRestServer $server)
{
if($server->getAuthType() !== Auth::AUTH_TYPE)
{
throw new AuthTypeException();
}
if(!CRestUtil::isAdmin())
{
throw new AccessException();
}
$query = array_change_key_case($query, CASE_LOWER);
$clearEvents = !isset($query['clear']) ? 1 : intval($query['clear']);
$processId = isset($query['process_id']) ? trim($query['process_id']) : null;
if(!$clearEvents && !static::isExtendedModeEnabled())
{
throw new LicenseException('extended offline events handling');
}
$filter = isset($query['filter']) ? $query['filter'] : array();
$order = isset($query['order']) ? $query['order'] : array('TIMESTAMP_X' => 'ASC');
$limit = isset($query['limit']) ? intval($query['limit']) : static::LIST_LIMIT;
$getErrors = isset($query['error']) && intval($query['error']) === 1;
$authData = $server->getAuthData();
$connectorId = isset($authData['auth_connector']) ? $authData['auth_connector'] : '';
$returnProcessId = !$clearEvents;
if($limit <= 0)
{
throw new ArgumentException('Value must be positive integer', 'LIMIT');
}
$queryFilter = static::sanitizeFilter($filter);
$order = static::sanitizeOrder($order);
$clientInfo = AppTable::getByClientId($server->getClientId());
$queryFilter['=APP_ID'] = $clientInfo['ID'];
$queryFilter['=CONNECTOR_ID'] = $connectorId;
$queryFilter['=ERROR'] = $getErrors ? 1 : 0;
if($processId === null)
{
$queryFilter['=PROCESS_ID'] = '';
$processId = EventOfflineTable::markEvents($queryFilter, $order, $limit);
}
else
{
$returnProcessId = true;
}
$queryFilter['=PROCESS_ID'] = $processId;
$dbRes = EventOfflineTable::getList(array(
'select' => array(
'ID', 'TIMESTAMP_X', 'EVENT_NAME', 'EVENT_DATA', 'EVENT_ADDITIONAL', 'MESSAGE_ID'
),
'filter' => $queryFilter,
'limit' => $limit,
'order' => $order,
));
$result = array();
while($event = $dbRes->fetch())
{
/** @var DateTime $ts */
$ts = $event['TIMESTAMP_X'];
$event['TIMESTAMP_X'] = CRestUtil::convertDateTime($ts->toString());
if (isset($event['EVENT_ADDITIONAL'][Auth::PARAM_LOCAL_USER]))
{
$event['EVENT_ADDITIONAL'] = [
'user_id' => $event['EVENT_ADDITIONAL'][Auth::PARAM_LOCAL_USER],
];
}
$result[] = $event;
}
if($clearEvents && count($result) > 0)
{
EventOfflineTable::clearEvents($processId, $clientInfo['ID'], $connectorId);
}
return array(
'process_id' => $returnProcessId ? $processId : null,
'events' => $result
);
}