• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/volume/foldertree.php
  • Класс: BitrixDiskVolumeFolderTree
  • Вызов: FolderTree::recalculatePercent
public function recalculatePercent($totalSizeIndicator = '\Bitrix\Disk\Volume\Storage\Storage', $excludeSizeIndicator = null): self
{
	if (is_string($totalSizeIndicator) && !empty($totalSizeIndicator) && class_exists($totalSizeIndicator))
	{
		/** @var VolumeStorageStorage $totalSizeIndicator */
		$totalSizeIndicator = new $totalSizeIndicator();
	}
	if (!($totalSizeIndicator instanceof VolumeIVolumeIndicator))
	{
		throw new BitrixMainArgumentException('Wrong parameter totalSizeIndicator');
	}

	$storageId = $this->getFilterValue('STORAGE_ID', '=@');

	$totalSizeIndicator->setOwner($this->getOwner());
	$totalSizeIndicator->addFilter('STORAGE_ID', $storageId);
	$totalSizeIndicator->loadTotals();

	if($totalSizeIndicator->getTotalSize() > 0)
	{
		$connection = Application::getConnection();
		$tableName = VolumeTable::getTableName();
		$filter = [
			'=INDICATOR_TYPE' => VolumeFolder::className(),
			'=OWNER_ID' => $this->getOwner(),
			'=STORAGE_ID' => $storageId,
			'>FILE_COUNT' => 0,
		];

		$where = Query::buildFilterSql(VolumeTable::getEntity(), $filter);

		$total = $totalSizeIndicator->getTotalSize() + $totalSizeIndicator->getPreviewSize();

		$sql = 'UPDATE '.$tableName.' SET PERCENT = ROUND((FILE_SIZE + PREVIEW_SIZE) * 100 / '.$total.', 4) WHERE '.$where;

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