• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/volume/base.php
  • Класс: Bitrix\Crm\Volume\Base
  • Вызов: Base::measureEntity
public function measureEntity()
{
	self::loadTablesInformation();

	// database size
	$this->entitySize = 0;
	$this->entityCount = 0;

	if (count($this->getFilter()) > 0)
	{
		if (!$this->canBeFiltered())
		{
			// nonfiterable
			return $this;
		}

		$entityList = static::getEntityList();
		foreach ($entityList as $classEntity)
		{
			/**
			 * @var ORM\Data\DataManager $classEntity
			 */
			$query = $classEntity::query();
			$entity = $classEntity::getEntity();

			// filter
			if ($this->prepareEntityFilter($query, $entity))
			{
				$query
					->registerRuntimeField(new ORM\Fields\ExpressionField('CNT', 'COUNT(*)'))
					->addSelect('CNT');

				$res = $query->exec();
				if ($row = $res->fetch())
				{
					$table = $classEntity::getTableName();
					$avgTableRowLength = (double)self::$tablesInformation[$table]['AVG_SIZE'];
					$this->entitySize += $avgTableRowLength * (double)$row['CNT'];
				}
			}
		}
	}
	else
	{
		$tableList = $this->getTableList();
		if (count($tableList) > 0)
		{
			$this->entityCount = self::$tablesInformation[$tableList[0]]['TABLE_ROWS'];

			foreach ($tableList as $tableName)
			{
				$this->entitySize += (double)self::$tablesInformation[$tableName]['SIZE'];
			}
		}
	}

	$connection = Main\Application::getConnection();

	$data = array(
		'INDICATOR_TYPE' => static::getIndicatorId(),
		'OWNER_ID' => $this->getOwner(),
		'ENTITY_COUNT' => ($this->entityCount ? : 0),
		'ENTITY_SIZE' => ($this->entitySize ? : 0),
		'STAGE_SEMANTIC_ID' => '-',
	);

	$insert = $connection->getSqlHelper()->prepareInsert(Crm\VolumeTable::getTableName(), $data);

	$querySql = 'INSERT INTO '.$connection->getSqlHelper()->quote(Crm\VolumeTable::getTableName()). '('. $insert[0]. ') VALUES ('. $insert[1]. ')';

	Crm\VolumeTable::deleteBatch(array(
		'=INDICATOR_TYPE' => static::getIndicatorId(),
		'=OWNER_ID' => $this->getOwner(),
		'=AGENT_LOCK' => Volume\Cleaner::TASK_STATUS_NONE,
	));

	$connection->queryExecute($querySql);

	return $this;
}