• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/volume/cleaner.php
  • Класс: BitrixDiskVolumeCleaner
  • Вызов: Cleaner::deleteFileByFilter
public function deleteFileByFilter(VolumeIVolumeIndicator $indicator): bool
{
	$subTaskDone = true;

	if ($indicator->getFilterValue('STORAGE_ID') > 0)
	{
		$storage = DiskStorage::loadById($indicator->getFilterValue('STORAGE_ID'));
		if (!($storage instanceof DiskStorage))
		{
			$this->collectError(
				new Error('Can not found storage #'.$indicator->getFilterValue('STORAGE_ID'), 'STORAGE_NOT_FOUND'),
				false,
				true
			);

			return false;
		}
		if (!$this->isAllowClearStorage($storage))
		{
			$this->collectError(
				new Error('Access denied to storage #'.$storage->getId(), 'ACCESS_DENIED'),
				false,
				true
			);

			return false;
		}
	}

	$task = $this->instanceTask();

	$filter = [];
	if ($task->getLastFileId() > 0)
	{
		$filter['>=ID'] = $task->getLastFileId();
	}

	$indicator->setLimit(self::MAX_FILE_PER_INTERACTION);

	$fileList = $indicator->getCorrespondingFileList($filter);

	$task->setIterationFileCount($fileList->getSelectedRowsCount());

	$countFileErasure = 0;

	foreach ($fileList as $row)
	{
		$fileId = $row['ID'];
		$file = DiskFile::getById($fileId);
		if ($file instanceof DiskFile)
		{
			if (!$this->isAllowClearFolder($file->getParent()))
			{
				$this->collectError(new Error("Access denied to file #$fileId", 'ACCESS_DENIED'));
			}
			else
			{
				$securityContext = $this->getSecurityContext($this->getOwner(), $file);
				if (!$file->canDelete($securityContext))
				{
					$this->collectError(new Error("Access denied to file #$fileId", 'ACCESS_DENIED'));
				}
				else
				{
					$this->deleteFile($file);
					$countFileErasure++;
				}
			}
		}

		$task->setLastFileId($fileId);

		// fix interval task state
		if ($countFileErasure >= self::STATUS_FIX_INTERVAL)
		{
			$countFileErasure = 0;

			if ($task->hasUserCanceled())
			{
				$subTaskDone = false;
				break;
			}

			$task->fixState();

			// count statistic for progress bar
			self::countWorker((int)$task->getOwnerId());
		}

		if (!$this->checkTimeEnd())
		{
			$subTaskDone = false;
			break;
		}
	}

	return $subTaskDone;
}