- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/lib/event/sender.php
- Класс: BitrixRestEventSender
- Вызов: Sender::call
static function call($handlersList)
{
global $USER;
$offlineEvents = array();
$logger = LoggerManager::getInstance()->getLogger();
if ($logger)
{
$logger->debug(
"n{delimiter}n"
. "{date} - {host}n{delimiter}n"
. " Sender::call() starts.n"
. "{handlersList}n{delimiter} ",
[
'handlersList' => $handlersList,
]
);
}
foreach($handlersList as $handlerInfo)
{
$handler = $handlerInfo[0];
$data = $handlerInfo[1];
$additional = $handlerInfo[2];
foreach(static::$defaultEventParams as $key => $value)
{
if(!isset($additional[$key]))
{
$additional[$key] = $value;
}
}
$session = Session::get();
if(!$session)
{
if ($logger)
{
$logger->debug(
"n{delimiter}n"
. "{date} - {host}n{delimiter}n"
. "Session ttl exceeded {session}.n",
[
'session' => $session,
]
);
}
// ttl exceeded, kill session
return;
}
$userId = $handler['USER_ID'] > 0
? $handler['USER_ID']
: (
// USER object can be null if event runs in BP or agent
is_object($USER) && $USER->isAuthorized()
? $USER->getId()
: 0
);
$authData = null;
if($handler['APP_ID'] > 0)
{
$dbRes = AppTable::getById($handler['APP_ID']);
$application = $dbRes->fetch();
$appStatus = BitrixRestAppTable::getAppStatusInfo($application, '');
if($appStatus['PAYMENT_ALLOW'] === 'Y')
{
$authData = array(
Session::PARAM_SESSION => $session,
Auth::PARAM_LOCAL_USER => $userId,
"application_token" => CRestUtil::getApplicationToken($application),
);
}
if($handler['EVENT_HANDLER'] <> '')
{
UsageStatTable::logEvent($application['CLIENT_ID'], $handler['EVENT_NAME']);
}
}
else
{
$application = array('CLIENT_ID' => null);
$authData = array(
Session::PARAM_SESSION => $session,
Auth::PARAM_LOCAL_USER => $userId,
'application_token' => $handler['APPLICATION_TOKEN'],
);
}
if($authData)
{
if($handler['EVENT_HANDLER'] <> '')
{
self::$queryData[] = Sqs::queryItem(
$application['CLIENT_ID'],
$handler['EVENT_HANDLER'],
array(
'event' => $handler['EVENT_NAME'],
'data' => $data,
'ts' => time(),
),
$authData,
$additional
);
}
else
{
$offlineEvents[] = array(
'HANDLER' => $handler,
'APPLICATION' => $application,
'AUTH' => $authData,
'DATA' => $data,
);
}
}
}
if (count($offlineEvents) > 0)
{
if ($logger)
{
$logger->debug(
"n{delimiter}n"
. "{date} - {host}n{delimiter}n"
. "Event count: {eventCount}n{delimiter}"
. "Offline event list:n"
. "{offlineEvents}",
[
'eventCount' => count($offlineEvents),
'offlineEvents' => $offlineEvents,
]
);
}
static::getProviderOffline()->send($offlineEvents);
}
if (count(static::$queryData) > 0 && !static::$forkSet)
{
if ($logger)
{
$logger->debug(
"n{delimiter}n"
. "{date} - {host}n{delimiter}n"
. "Registers send event background job.n"
. "count: {eventCount}",
[
'eventCount' => count(static::$queryData),
]
);
}
BitrixMainApplication::getInstance()->addBackgroundJob(array(__CLASS__, "send"));
static::$forkSet = true;
}
}