59 protected static $data = array();
68 return 'b_rest_usage_stat';
80 'data_type' =>
'date',
84 'data_type' =>
'integer',
88 'data_type' =>
'boolean',
95 'data_type' =>
'integer',
99 'data_type' =>
'integer',
103 'data_type' =>
'integer',
107 'data_type' =>
'integer',
111 'data_type' =>
'integer',
115 'data_type' =>
'integer',
119 'data_type' =>
'integer',
123 'data_type' =>
'integer',
127 'data_type' =>
'integer',
131 'data_type' =>
'integer',
135 'data_type' =>
'integer',
139 'data_type' =>
'integer',
143 'data_type' =>
'integer',
147 'data_type' =>
'integer',
151 'data_type' =>
'integer',
155 'data_type' =>
'integer',
159 'data_type' =>
'integer',
163 'data_type' =>
'integer',
167 'data_type' =>
'integer',
171 'data_type' =>
'integer',
175 'data_type' =>
'integer',
179 'data_type' =>
'integer',
183 'data_type' =>
'integer',
187 'data_type' =>
'integer',
191 'data_type' =>
'Bitrix\Rest\UsageEntityTable',
192 'reference' => array(
193 '=this.ENTITY_ID' =>
'ref.ID',
199 public static function log(\CRestServer $server)
206 if ($server->getClientId())
208 static::logMethod($server->getClientId(), $server->getMethod());
210 elseif ($server->getPasswordId())
212 static::logHookMethod($server->getPasswordId(), $server->getMethod());
221 public static function logMethod($clientId, $methodName)
226 public static function logEvent($clientId, $eventName)
236 public static function logRobot($clientId, $clientCode)
246 public static function logBizProc($clientId,
string $clientCode): void
276 public static function logLanding($clientId, $type, $count = 1)
278 static::incrementByCount(
295 static::incrementByCount(
306 static::incrementByCount(
325 protected static function incrementByCount($entityType, $entityId, $subEntityType, $subEntityName,
int $count)
327 $entityKey = static::getEntityKey($entityType, $entityId, $subEntityType, $subEntityName);
328 if (!isset(static::$data[$entityKey]))
330 static::$data[$entityKey] = 0;
332 static::$data[$entityKey] += $count;
335 protected static function increment($entityType, $entityId, $subEntityType, $subEntityName)
337 $entityKey = static::getEntityKey($entityType, $entityId, $subEntityType, $subEntityName);
338 if (!isset(static::$data[$entityKey]))
340 static::$data[$entityKey] = 0;
342 static::$data[$entityKey]++;
345 protected static function getEntityKey($entityType, $entityId, $subEntityType, $subEntityName)
347 return $entityType .
"|" . $entityId .
"|" . $subEntityType .
"|" . $subEntityName;
357 $connection = Main\Application::getConnection();
358 $helper = $connection->getSqlHelper();
360 $hour = intval(date(
'G'));
363 ksort(static::$data);
364 foreach (static::$data as $entityKey => $count)
366 list($entityType, $entityId, $subEntityType, $subEntityName) = explode(
"|", $entityKey, 4);
378 $insertFields = array(
379 'STAT_DATE' => $curDateSql,
380 'ENTITY_ID' => $statId,
381 'HOUR_'.$hour => $count,
383 $updateFields = array(
384 'HOUR_'.$hour =>
new Main\DB\
SqlExpression(
'?#+?i',
'HOUR_'.$hour, $count)
387 $queries = $helper->prepareMerge(static::getTableName(), array(
390 ), $insertFields, $updateFields);
392 foreach ($queries as $query)
394 $connection->queryExecute($query);
404 static::$data = array();
413 $entity = static::getEntity();
414 $sqlHelper = $entity->getConnection()->getSqlHelper();
415 $sqlTableName = static::getTableName();
417 $update = $sqlHelper->prepareUpdate($sqlTableName, $fields);
418 $where = Main\Entity\Query::buildFilterSql($entity, $filter);
419 if ($where <>
'' && $update[0] <>
'')
421 $sql =
"UPDATE {$sqlTableName} SET $update[0] WHERE $where";
422 $entity->getConnection()->queryExecute($sql);
431 $entity = static::getEntity();
432 $sqlTableName = static::getTableName();
434 $where = Main\Entity\Query::buildFilterSql($entity, $filter);
437 $sql =
"DELETE FROM {$sqlTableName} WHERE ".$where;
438 $entity->getConnection()->queryExecute($sql);
447 static::deleteByFilter(array(
448 "<STAT_DATE" => $date,
452 return "\\Bitrix\\Rest\\UsageStatTable::cleanUpAgent();";
457 $connection = \Bitrix\Main\Application::getConnection();
458 $helper = $connection->getSqlHelper();
459 $sqlTableName = static::getTableName();
462 SELECT MIN(STAT_DATE) STAT_DATE_MIN
465 AND (STAT_DATE < ".$helper->getCurrentDateFunction().
")
467 $result = $connection->query($select);
468 $date = $result->fetch();
469 if($date && $date[
"STAT_DATE_MIN"])
471 if (static::sendDateStat($date[
"STAT_DATE_MIN"]))
473 static::updateByFilter(array(
"=STAT_DATE" => $date[
"STAT_DATE_MIN"]), array(
"IS_SENT" =>
"Y"));
476 return "\\Bitrix\\Rest\\UsageStatTable::sendAgent();";
483 $statList = static::getList(array(
485 "ENTITY_ID" =>
"ENTITY_ID",
486 "ENTITY_TYPE" =>
"ENTITY.ENTITY_TYPE",
487 "ENTITY_CODE" =>
"ENTITY.ENTITY_CODE",
488 "SUB_ENTITY_TYPE" =>
"ENTITY.SUB_ENTITY_TYPE",
489 "SUB_ENTITY_NAME" =>
"ENTITY.SUB_ENTITY_NAME",
517 "=STAT_DATE" => $date,
522 while ($dayStat = $statList->fetch())
524 if ($dayStat[
"ENTITY_CODE"] && $dayStat[
"STAT_DATE"])
526 $dayStat[
"STAT_DATE"] = $dayStat[
"STAT_DATE"]->format(
"Y-m-d");
527 $dayStat[
'HOUR_TOTAL'] = 0;
528 for ($i = 0; $i < 24; $i++)
530 $dayStat[
'HOUR_TOTAL'] += (int)$dayStat[
'HOUR_' . $i];
531 unset($dayStat[
'HOUR_' . $i]);
539 $response = \Bitrix\Rest\OAuthService::getEngine()->getClient()->sendApplicationUsage($usage);
540 $return = is_array($response) && $response[
'result'] ===
true;
static isModuleInstalled($moduleName)
static register($entityType, $entityId, $subEntityType, $subEntityName)
const ENTITY_TYPE_WEBHOOK
const SUB_ENTITY_TYPE_ROBOT
const SUB_ENTITY_TYPE_BI_SUPERSET
const SUB_ENTITY_TYPE_CONFIGURATION
const SUB_ENTITY_TYPE_LANDING_KNOWLEDGE
const SUB_ENTITY_TYPE_METHOD
const SUB_ENTITY_TYPE_PLACEMENT
const SUB_ENTITY_TYPE_BIZ_PROC
const SUB_ENTITY_TYPE_SEND_MESSAGE
const ENTITY_TYPE_APPLICATION
const SUB_ENTITY_TYPE_EVENT
const SUB_ENTITY_TYPE_LANDING
const SUB_ENTITY_TYPE_ACTIVITY
static getEntityKey($entityType, $entityId, $subEntityType, $subEntityName)
static logBizProc($clientId, string $clientCode)
static logHookMethod($passwordID, $methodName)
static logLanding($clientId, $type, $count=1)
static logActivity($clientId, $clientCode)
static log(\CRestServer $server)
static deleteByFilter(array $filter)
static updateByFilter(array $filter, array $fields)
static logMessage($clientId, $messageType)
static logBISuperset(string $clientId, string $type)
static logEvent($clientId, $eventName)
static sendDateStat($date)
static increment($entityType, $entityId, $subEntityType, $subEntityName)
static logConfiguration($clientId, $clientCode)
static logLandingKnowledge($clientId, string $type, int $count=1)
static logUserInterface($clientId, string $type, int $count=1)
static incrementByCount($entityType, $entityId, $subEntityType, $subEntityName, int $count)
static logMethod($clientId, $methodName)
static logPlacement($clientId, $placementName)
static logRobot($clientId, $clientCode)