|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | +/** |
| 4 | + * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl> |
| 5 | + * |
| 6 | + * @license GNU AGPL version 3 or any later version |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +namespace OCA\Files_Trashbin\Sabre; |
| 24 | + |
| 25 | +use OCA\Files_Trashbin\Trash\ITrashItem; |
| 26 | +use OCP\Files\FileInfo; |
| 27 | +use Sabre\DAV\Exception\Forbidden; |
| 28 | +use Sabre\DAV\Exception\NotFound; |
| 29 | +use Sabre\DAV\ICollection; |
| 30 | + |
| 31 | +abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash { |
| 32 | + public function getChildren(): array { |
| 33 | + $entries = $this->trashManager->listTrashFolder($this->user, $this->data); |
| 34 | + |
| 35 | + $children = array_map(function (ITrashItem $entry) { |
| 36 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
| 37 | + return new TrashFolderFolder($this->trashManager, $this->user, $entry); |
| 38 | + } |
| 39 | + return new TrashFolderFile($this->trashManager, $this->user, $entry); |
| 40 | + }, $entries); |
| 41 | + |
| 42 | + return $children; |
| 43 | + } |
| 44 | + |
| 45 | + public function getChild($name): ITrash { |
| 46 | + $entries = $this->getChildren(); |
| 47 | + |
| 48 | + foreach ($entries as $entry) { |
| 49 | + if ($entry->getName() === $name) { |
| 50 | + return $entry; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + throw new NotFound(); |
| 55 | + } |
| 56 | + |
| 57 | + public function childExists($name): bool { |
| 58 | + try { |
| 59 | + $this->getChild($name); |
| 60 | + return true; |
| 61 | + } catch (NotFound $e) { |
| 62 | + return false; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + public function setName($name) { |
| 67 | + throw new Forbidden(); |
| 68 | + } |
| 69 | + |
| 70 | + public function createFile($name, $data = null) { |
| 71 | + throw new Forbidden(); |
| 72 | + } |
| 73 | + |
| 74 | + public function createDirectory($name) { |
| 75 | + throw new Forbidden(); |
| 76 | + } |
| 77 | +} |
0 commit comments