- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/volume/base.php
- Класс: Bitrix\Crm\Volume\Base
- Вызов: Base::measureFiles
public function measureFiles()
{
$this->fileSize = 0;
$this->fileCount = 0;
$this->diskSize = 0;
$this->diskCount = 0;
if (count($this->getFilter()) > 0 && !$this->canBeFiltered())
{
// nonfiterable
return $this;
}
self::loadTablesInformation();
$connection = Main\Application::getConnection();
$source = array();
$entityList = static::getEntityList();
foreach ($entityList as $entityClass)
{
$entityUserFieldList = $this->getUserTypeFieldList($entityClass);
/** @var array $userField */
foreach ($entityUserFieldList as $userField)
{
$sql = $this->prepareUserFieldQuery($entityClass, $userField);
if ($sql !== '')
{
$source[] = $sql;
}
}
$diskConnector = static::getDiskConnector($entityClass);
if ($diskConnector !== null)
{
$sql = $this->prepareDiskAttachedQuery($entityClass, $diskConnector);
if ($sql !== '')
{
$source[] = $sql;
}
}
$liveFeedConnector = static::getLiveFeedConnector($entityClass);
if ($liveFeedConnector !== null)
{
$sql = $this->prepareLiveFeedQuery($entityClass, $liveFeedConnector);
if ($sql !== '')
{
$source[] = $sql;
}
}
}
if (count($source) > 0)
{
$querySql = "
SELECT
SUM(src.FILE_SIZE) as FILE_SIZE,
SUM(src.FILE_COUNT) as FILE_COUNT,
SUM(src.DISK_SIZE) as DISK_SIZE,
SUM(src.DISK_COUNT) as DISK_COUNT
FROM
(
(". implode(' ) UNION ( ', $source). ")
) src
";
$result = $connection->query($querySql);
if ($row = $result->fetch())
{
$this->fileSize += (double)$row['FILE_SIZE'];
$this->fileCount += (double)$row['FILE_COUNT'];
$this->diskSize += (double)$row['DISK_SIZE'];
$this->diskCount += (double)$row['DISK_COUNT'];
}
}
$data = array(
'INDICATOR_TYPE' => static::getIndicatorId(),
'OWNER_ID' => $this->getOwner(),
'STAGE_SEMANTIC_ID' => '-',
'FILE_SIZE' => $this->fileSize,
'FILE_COUNT' => $this->fileCount,
'DISK_SIZE' => $this->diskSize,
'DISK_COUNT' => $this->diskCount,
);
$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;
}