|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl> |
| 4 | + * |
| 5 | + * @author Roeland Jago Douma <roeland@famdouma.nl> |
| 6 | + * |
| 7 | + * @license GNU AGPL version 3 or any later version |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License as |
| 11 | + * published by the Free Software Foundation, either version 3 of the |
| 12 | + * License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Affero General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Affero General Public License |
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + * |
| 22 | + */ |
| 23 | +namespace OCA\Files_Trashbin\Sabre; |
| 24 | + |
| 25 | +use OCP\Files\FileInfo; |
| 26 | +use Sabre\DAV\Exception\Forbidden; |
| 27 | +use Sabre\DAV\ICollection; |
| 28 | + |
| 29 | +class TrashFolder implements ICollection { |
| 30 | + /** @var string */ |
| 31 | + private $userId; |
| 32 | + |
| 33 | + /** @var FileInfo */ |
| 34 | + private $data; |
| 35 | + |
| 36 | + public function __construct(string $root, string $userId, FileInfo $data) { |
| 37 | + $this->userId = $userId; |
| 38 | + $this->data = $data; |
| 39 | + } |
| 40 | + |
| 41 | + public function createFile($name, $data = null) { |
| 42 | + throw new Forbidden(); |
| 43 | + } |
| 44 | + |
| 45 | + public function createDirectory($name) { |
| 46 | + throw new Forbidden(); |
| 47 | + } |
| 48 | + |
| 49 | + public function getChild($name) { |
| 50 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
| 51 | + |
| 52 | + foreach ($entries as $entry) { |
| 53 | + if ($entry->getName() === $name) { |
| 54 | + if ($entry->getMimetype() === 'httpd/unix-directory') { |
| 55 | + return new TrashFolderFolder($this->getName(), $this->userId, $entry); |
| 56 | + } |
| 57 | + return new TrashFolderFile($this->getName(), $this->userId, $entry); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public function getChildren() { |
| 63 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
| 64 | + |
| 65 | + $children = array_map(function (FileInfo $entry) { |
| 66 | + if ($entry->getMimetype() === 'httpd/unix-directory') { |
| 67 | + return new TrashFolderFolder($this->getName(), $this->userId, $entry); |
| 68 | + } |
| 69 | + return new TrashFolderFile($this->getName(), $this->userId, $entry); |
| 70 | + }, $entries); |
| 71 | + |
| 72 | + return $children; |
| 73 | + } |
| 74 | + |
| 75 | + public function childExists($name) { |
| 76 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
| 77 | + |
| 78 | + foreach ($entries as $entry) { |
| 79 | + if ($entry->getName() === $name) { |
| 80 | + return true; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + return false; |
| 85 | + } |
| 86 | + |
| 87 | + public function delete() { |
| 88 | + \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); |
| 89 | + } |
| 90 | + |
| 91 | + public function getName() { |
| 92 | + return $this->data->getName() . '.d' . $this->getLastModified(); |
| 93 | + } |
| 94 | + |
| 95 | + public function setName($name) { |
| 96 | + throw new Forbidden(); |
| 97 | + } |
| 98 | + |
| 99 | + public function getLastModified() { |
| 100 | + return $this->data->getMtime(); |
| 101 | + } |
| 102 | +} |
0 commit comments