• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
  • Класс: BitrixDiskUfController
  • Вызов: Controller::processActionDeleteFile
protected function processActionDeleteFile($attachedId)
{
	if($this->errorCollection->hasErrors())
	{
		$this->sendJsonErrorResponse();
	}

	[$type, $realValue] = FileUserType::detectType($attachedId);

	if ($type == FileUserType::TYPE_NEW_OBJECT)
	{
		$file = File::loadById((int)$realValue, array('STORAGE'));
		if(!$file)
		{
			$this->errorCollection->add(array(new Error("Could not find file")));
			$this->sendJsonErrorResponse();
		}

		if(!$file->canDelete($file->getStorage()->getCurrentUserSecurityContext()))
		{
			$this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
			$this->sendJsonErrorResponse();
		}

		if($file->countAttachedObjects() != 0)
		{
			$this->errorCollection->add(array(new Error('Could not delete file which attached to entities')));
			$this->sendJsonErrorResponse();
		}

		if($file->getGlobalContentVersion() != 1)
		{
			$this->errorCollection->add(array(new Error('Could not delete file which has a few versions')));
			$this->sendJsonErrorResponse();
		}

		if(!$file->getParent() ||
			$file->getParent()->getCode() != Folder::CODE_FOR_UPLOADED_FILES
		)
		{
			$this->errorCollection->add(array(new Error('Could not delete file which is not located in folder for uploaded files.')));
			$this->sendJsonErrorResponse();
		}

		if(!$file->delete($this->getUser()->getId()))
		{
			$this->errorCollection->add($file->getErrors());
			$this->sendJsonErrorResponse();
		}

		$this->sendJsonSuccessResponse(array(
			'id' => $attachedId,
		));
	}
	else
	{
		$this->errorCollection->add(array(new Error('Could not delete attached object')));
		$this->sendJsonErrorResponse();
	}
}