3namespace Bitrix\Rest\Event;
5use Bitrix\Main\Context;
7use Bitrix\Main\EventManager;
8use Bitrix\Rest\Application;
9use Bitrix\Rest\AppTable;
10use Bitrix\Rest\OAuth\Auth;
11use Bitrix\Rest\OAuthService;
13use Bitrix\Rest\Tools\Diagnostics\Event\Logger;
14use Bitrix\Rest\Tools\Diagnostics\Event\LogType;
15use Bitrix\Rest\UsageStatTable;
16use Bitrix\Rest\Tools\Diagnostics\LoggerManager;
44 "sendRefreshToken" =>
false,
61 $res[
'EVENT'] = str_replace(
'_0_',
'\\',
$res[
'EVENT']);
62 $res[
'EVENT'] = str_replace(
'_1_',
'::',
$res[
'EVENT']);
101 return static::$defaultEventParams;
121 if(
$userId > 0 && $additional[
"sendAuth"])
127 if(is_array(
$auth) && !$additional[
"sendRefreshToken"])
129 unset(
$auth[
'refresh_token']);
137 "domain" => Context::getCurrent()->getRequest()->getHttpHost(),
138 "member_id" => \CRestUtil::getMemberId()
157 public static function call($handlersList)
161 $offlineEvents =
array();
162 LoggerManager::getInstance()->getLogger()?->debug(
164 .
"{date} - {host}\n{delimiter}\n"
165 .
" Sender::call() starts.\n"
166 .
"{handlersList}\n{delimiter} ", [
167 'handlersList' => $handlersList,
168 'MESSAGE' => LogType::SENDER_CALL_START->value,
171 foreach($handlersList as $handlerInfo)
173 $handler = $handlerInfo[0];
174 $data = $handlerInfo[1];
175 $additional = $handlerInfo[2];
177 foreach(static::$defaultEventParams as
$key => $value)
179 if(!isset($additional[
$key]))
181 $additional[
$key] = $value;
188 LoggerManager::getInstance()->getLogger()?->info(
190 .
"{date} - {host}\n{delimiter}\n"
191 .
"Session ttl exceeded {session}.\n", [
192 'session' => $session,
193 'MESSAGE' => LogType::CYCLIC_CALL_LIMIT->value,
200 $userId = $handler[
'USER_ID'] > 0
201 ? $handler[
'USER_ID']
210 if(isset($handler[
'APP_ID']) && $handler[
'APP_ID'] > 0)
212 if (isset(static::$appData[$handler[
'APP_ID']]) && is_array(static::$appData[$handler[
'APP_ID']]))
230 $dbRes = AppTable::getByPrimary($handler[
'APP_ID'], [
'select' =>
$select]);
237 if($appStatus[
'PAYMENT_ALLOW'] ===
'Y')
241 Auth::PARAM_LOCAL_USER =>
$userId,
242 "application_token" => \CRestUtil::getApplicationToken(
$application),
246 if($handler[
'EVENT_HANDLER'] <>
'')
257 Auth::PARAM_LOCAL_USER =>
$userId,
258 'application_token' => $handler[
'APPLICATION_TOKEN'],
264 if ($handler[
'EVENT_HANDLER'] !==
'')
268 $handler[
'EVENT_HANDLER'],
269 $handler[
'EVENT_NAME'],
275 if ($eventBufferAddResult->isSuccess())
279 $handler[
'EVENT_HANDLER'],
281 'event' => $handler[
'EVENT_NAME'],
282 'event_handler_id' => $handler[
'ID'],
293 $offlineEvents[] =
array(
294 'HANDLER' => $handler,
303 if (
count($offlineEvents) > 0)
305 LoggerManager::getInstance()->getLogger()?->debug(
307 .
"{date} - {host}\n{delimiter}\n"
308 .
"Event count: {eventCount}\n{delimiter}"
309 .
"Offline event list:\n"
310 .
"{offlineEvents}", [
311 'eventCount' =>
count($offlineEvents),
312 'offlineEvents' => $offlineEvents,
313 'MESSAGE' => LogType::READY_OFFLINE_EVENT_LIST->value,
315 static::getProviderOffline()->send($offlineEvents);
318 if (
count(static::$queryData) > 0)
320 self::enqueueBackgroundJob();
327 public static function send(): void
329 LoggerManager::getInstance()->getLogger()?->debug(
331 .
"{date} - {host}\n{delimiter}\n"
332 .
"Starts method Sender::send()\n"
333 .
"count: {eventCount}"
336 'eventCount' =>
count(static::$queryData),
337 'eventList' => static::$queryData,
338 'MESSAGE' => LogType::SENDER_SEND_START->value,
340 if (
count(self::$queryData) > 0)
343 static::getProvider()->send(self::$queryData);
344 self::$queryData = [];
345 self::$forkSet =
false;
351 self::$queryData[] = $queryItem;
352 self::enqueueBackgroundJob();
360 static::initialize();
362 if(!static::$provider)
364 static::$provider = static::getDefaultProvider();
367 return static::$provider;
388 static::initialize();
390 if(!static::$providerOffline)
392 static::$providerOffline = static::getDefaultProviderOffline();
395 return static::$providerOffline;
408 if (!static::$forkSet)
410 LoggerManager::getInstance()->getLogger()?->debug(
412 .
"{date} - {host}\n{delimiter}\n"
413 .
"Registers the background job to send the event.\n"
414 .
"count: {eventCount}", [
415 'eventCount' =>
count(static::$queryData),
416 'MESSAGE' => LogType::READY_ONLINE_EVENT_LIST->value,
420 job: [__CLASS__,
'send'],
421 priority: $application::JOB_PRIORITY_LOW
423 static::$forkSet =
true;
434 if(!static::$initialized)
436 static::$initialized =
true;
438 $event =
new Event(
'rest',
'onEventManagerInitialize');
446 if(mb_strpos($eventName,
'::') >= 0)
448 $handlerName =
$moduleId.
'__'.mb_strtoupper(str_replace(
array(
"\\",
'::'),
array(
'_0_',
'_1_'), $eventName));
452 $handlerName =
$moduleId.
'__'.mb_strtoupper($eventName);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getAppStatusInfo($app, $detailUrl)
static getByClientId($clientId)
static queueEvent($queryItem)
static bind($moduleId, $eventName)
static parseEventName($name)
static getHandlerName($moduleId, $eventName)
static $defaultEventParams
static setProviderOffline(ProviderOfflineInterface $providerOffline)
static getAuth($appId, $userId, array $additionalData=array(), array $additional=array())
static getDefaultEventParams()
static getProviderOffline()
static call($handlersList)
static enqueueBackgroundJob()
static unbind($moduleId, $eventName)
static getDefaultProviderOffline()
static setProvider(ProviderInterface $provider)
static getDefaultProvider()
static queryItem($clientId, $url, $data, array $authData=array(), array $additional=array())
static logEvent($clientId, $eventName)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"