• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/file.php
  • Класс: CWebDavFile
  • Вызов: CWebDavFile::DELETE
function DELETE($options)
{
	$io = self::GetIo();
	if (isset($options['path']))
		$options['path'] = $this->_udecode($options['path']);
	$this->IsDir($options);
	if ($this->arParams["not_found"])
	{
		$GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
		return "404 Not found";
	}

	if(!$this->CheckRights("DELETE", true, $options["path"]))
	{
		$this->ThrowAccessDenied();
		return "403 Forbidden";
	}

	$quota = false;
	if (COption::GetOptionInt("main", "disk_space") > 0)
		$quota = new CDiskQuota();

	$trashPath = $this->GetMetaID("TRASH");
	$arPath = explode("/", $this->arParams["item_id"]);
	if (!$this->arParams["is_dir"])
	{

		//$file = $io->CombinePath($this->real_path_full, $this->arParams["item_id"]);
		//$path = $io->CombinePath($this->real_path, $this->arParams["item_id"]);

		$file = CWebDavBase::CleanRelativePathString($this->arParams["item_id"], $this->real_path_full);
		$path = CWebDavBase::CleanRelativePathString($this->arParams["item_id"], $this->real_path);
		if($file === false || $path === false)
		{
			return "404 Not found";
		}

		$arPath = explode("/", $this->arParams["item_id"]);
		if (($arPath[1] != $this->meta_names["TRASH"]["name"]) && (!isset($options['force'])))		   // not in trash yet
		{
			return $this->_move_to_trash($options, $this->arParams);
		} else {											 // in trash or options[force]
			$oFile = $io->GetFile($file);
			$file_size = $oFile->GetFileSize();
			if ($io->Delete($file))
			{
				$this->_delete_props($this->arParams['item_id']);
				$GLOBALS["APPLICATION"]->RemoveFileAccessPermission(Array(SITE_ID, $path));

				if (CModule::IncludeModule("search"))
					CSearch::DeleteIndex("main", SITE_ID."|".$path);
				if ($quota)
					$quota->updateDiskQuota("file", $file_size, "delete");
			}
			else
			{
				$GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
				return "404 Not found";
			}
		}
	}
	else
	{
		if (($arPath[1] != $this->meta_names["TRASH"]["name"]) && (!isset($options['force'])))
		{
			return $this->_move_to_trash($options, $this->arParams);
		}
		else
		{
			$params = $this->GetFilesAndFolders($this->arParams["item_id"]);
			if (empty($params))
				return true;

			rsort($params, SORT_STRING);
			foreach ($params as $file)
			{

				$path = str_replace($this->real_path_full, "", $file);
				$path = $io->CombinePath("/", $path);
				$file = $io->CombinePath($this->real_path_full, $path);
				if(!$io->ValidatePathString($file))
				{
					return "404 Not found";
				}

				if ($io->FileExists($file))
				{
					//$path = str_replace($_SERVER['DOCUMENT_ROOT'], "", $file);
					$oFile = $io->GetFile($file);
					$file_size = $oFile->GetFileSize();
					if ($io->Delete($file))
					{
						$this->_delete_props(str_replace(array($this->real_path_full, "///", "//"), "/", $file));
						$GLOBALS["APPLICATION"]->RemoveFileAccessPermission(Array(SITE_ID, $path));
						if (CModule::IncludeModule("search"))
							CSearch::DeleteIndex("main", SITE_ID."|".$path);
						if ($quota)
							$quota->updateDiskQuota("file", $file_size, "delete");
					}
					else
					{
						$GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
						return "404 Not found";
					}
				}
				elseif ($io->DirectoryExists($file))
				{
					$path = str_replace($_SERVER['DOCUMENT_ROOT'], "", $file);
					if ($io->Delete($file))
					{
						$this->_delete_props(str_replace(array($this->real_path_full, "///", "//"), "/", $file));
						$GLOBALS["APPLICATION"]->RemoveFileAccessPermission(Array(SITE_ID, $path));
					}
					else
					{
						$GLOBALS["APPLICATION"]->ThrowException(GetMessage("WD_FILE_ERROR3"), "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND");
						return "404 Not found";
					}
				}
			}

			if ($path == $trashPath) //  all the trash was cleaned
			{
				$trashID = $this->GetMetaID('TRASH');
			}
		}
	}
	clearstatcache();
	return "204 No Content";
}