• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/volume/storage/storage.php
  • Класс: BitrixDiskVolumeStorageStorage
  • Вызов: Storage::recalculatePercent
public function recalculatePercent($totalSizeIndicator = '\Bitrix\Disk\Volume\Module\Disk', $excludeSizeIndicator = ''): self
{
	if (is_string($totalSizeIndicator) && !empty($totalSizeIndicator) && class_exists($totalSizeIndicator))
	{
		/** @var VolumeModuleDisk $totalSizeIndicator */
		$totalSizeIndicator = new $totalSizeIndicator();
	}
	if (!($totalSizeIndicator instanceof VolumeIVolumeIndicator))
	{
		throw new BitrixMainArgumentException('Wrong parameter totalSizeIndicator');
	}
	$totalSizeIndicator->setOwner($this->getOwner());
	$totalSizeIndicator->loadTotals();
	$total = $totalSizeIndicator->getTotalSize() + $totalSizeIndicator->getPreviewSize();

	if (is_string($excludeSizeIndicator) && !empty($excludeSizeIndicator) && class_exists($excludeSizeIndicator))
	{
		/** @var VolumeModuleDiskTrashcan $excludeSizeIndicator */
		$excludeSizeIndicator = new $excludeSizeIndicator();
	}
	if ($excludeSizeIndicator instanceof VolumeIVolumeIndicator)
	{
		/** @var string|VolumeIVolumeIndicator $excludeSizeIndicator */
		$excludeSizeIndicator->setOwner($this->getOwner());
		$excludeSizeIndicator->loadTotals();
		$total -= $excludeSizeIndicator->getTotalSize();
		$total -= $excludeSizeIndicator->getPreviewSize();
	}

	if ($total > 0)
	{
		$tableName = VolumeTable::getTableName();
		$connection = Application::getConnection();

		$ownerId = $this->getOwner();
		$classStorage = $connection->getSqlHelper()->forSql(static::className());
		$classTrashcan = $connection->getSqlHelper()->forSql(VolumeStorageTrashCan::className());

		$sql = "
			UPDATE 
				{$tableName} destinationTbl, 
				(
					SELECT 
						Storage.ID,
						Storage.STORAGE_ID,
						ifnull(Storage.FILE_SIZE, 0) + ifnull(Trashcan.FILE_SIZE, 0) as FILE_SIZE 
					FROM
					(
						SELECT ID, STORAGE_ID, FILE_SIZE + ifnull(PREVIEW_SIZE, 0) as FILE_SIZE
						FROM 
							{$tableName} 
						WHERE 
							OWNER_ID = {$ownerId}
							AND INDICATOR_TYPE = '{$classStorage}'
					) Storage
					LEFT JOIN
					(
						SELECT STORAGE_ID, FILE_SIZE + ifnull(PREVIEW_SIZE, 0) as FILE_SIZE
						FROM 
							{$tableName} 
						WHERE 
							OWNER_ID = {$ownerId}
							AND INDICATOR_TYPE = '{$classTrashcan}'
					) Trashcan
					ON Storage.STORAGE_ID = Trashcan.STORAGE_ID
				) sourceQuery 
			SET 
				destinationTbl.PERCENT = ROUND(sourceQuery.FILE_SIZE * 100 / {$total}, 4)  
			WHERE 
				destinationTbl.ID = sourceQuery.ID
				AND destinationTbl.storage_id = sourceQuery.storage_id
		";

		if ($connection->lock(self::$lockName, self::$lockTimeout))
		{
			$connection->queryExecute($sql);
			$connection->unlock(self::$lockName);
		}
	}

	return $this;
}