• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/lib/usagestat.php
  • Класс: BitrixRestUsageStatTable
  • Вызов: UsageStatTable::finalize
static function finalize()
{
	if (MainModuleManager::isModuleInstalled('oauth'))
	{
		return;
	}

	$connection = MainApplication::getConnection();
	$helper = $connection->getSqlHelper();

	$hour = intval(date('G'));
	$curDateSql = new MainTypeDate();

	ksort(static::$data);
	foreach (static::$data as $entityKey => $count)
	{
		list($entityType, $entityId, $subEntityType, $subEntityName) = explode("|", $entityKey, 4);
		try
		{
			$statId = UsageEntityTable::register($entityType, $entityId, $subEntityType, $subEntityName);
		}
		catch (SqlQueryException $e)
		{
			$statId = false;
		}

		if ($statId)
		{
			$insertFields = array(
				'STAT_DATE' => $curDateSql,
				'ENTITY_ID' => $statId,
				'HOUR_'.$hour => $count,
			);
			$updateFields = array(
				'HOUR_'.$hour => new MainDBSqlExpression('?#+?i', 'HOUR_'.$hour, $count)
			);

			$queries = $helper->prepareMerge(static::getTableName(), array(
					'STAT_DATE',
					'ENTITY_ID'
				), $insertFields, $updateFields);

			foreach ($queries as $query)
			{
				$connection->queryExecute($query);
			}
		}
	}

	static::reset();
}