@@ -37,75 +37,75 @@ |
||
| 37 | 37 | |
| 38 | 38 | class TrashRoot implements ICollection { |
| 39 | 39 | |
| 40 | - /** @var IUser */ |
|
| 41 | - private $user; |
|
| 42 | - |
|
| 43 | - /** @var ITrashManager */ |
|
| 44 | - private $trashManager; |
|
| 45 | - |
|
| 46 | - public function __construct(IUser $user, ITrashManager $trashManager) { |
|
| 47 | - $this->user = $user; |
|
| 48 | - $this->trashManager = $trashManager; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function delete() { |
|
| 52 | - \OCA\Files_Trashbin\Trashbin::deleteAll(); |
|
| 53 | - foreach ($this->trashManager->listTrashRoot($this->user) as $trashItem) { |
|
| 54 | - $this->trashManager->removeItem($trashItem); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function getName(): string { |
|
| 59 | - return 'trash'; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function setName($name) { |
|
| 63 | - throw new Forbidden('Permission denied to rename this trashbin'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function createFile($name, $data = null) { |
|
| 67 | - throw new Forbidden('Not allowed to create files in the trashbin'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function createDirectory($name) { |
|
| 71 | - throw new Forbidden('Not allowed to create folders in the trashbin'); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public function getChildren(): array { |
|
| 75 | - $entries = $this->trashManager->listTrashRoot($this->user); |
|
| 76 | - |
|
| 77 | - $children = array_map(function (ITrashItem $entry) { |
|
| 78 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 79 | - return new TrashFolder($this->trashManager, $entry); |
|
| 80 | - } |
|
| 81 | - return new TrashFile($this->trashManager, $entry); |
|
| 82 | - }, $entries); |
|
| 83 | - |
|
| 84 | - return $children; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function getChild($name): ITrash { |
|
| 88 | - $entries = $this->getChildren(); |
|
| 89 | - |
|
| 90 | - foreach ($entries as $entry) { |
|
| 91 | - if ($entry->getName() === $name) { |
|
| 92 | - return $entry; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - throw new NotFound(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function childExists($name): bool { |
|
| 100 | - try { |
|
| 101 | - $this->getChild($name); |
|
| 102 | - return true; |
|
| 103 | - } catch (NotFound $e) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getLastModified(): int { |
|
| 109 | - return 0; |
|
| 110 | - } |
|
| 40 | + /** @var IUser */ |
|
| 41 | + private $user; |
|
| 42 | + |
|
| 43 | + /** @var ITrashManager */ |
|
| 44 | + private $trashManager; |
|
| 45 | + |
|
| 46 | + public function __construct(IUser $user, ITrashManager $trashManager) { |
|
| 47 | + $this->user = $user; |
|
| 48 | + $this->trashManager = $trashManager; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function delete() { |
|
| 52 | + \OCA\Files_Trashbin\Trashbin::deleteAll(); |
|
| 53 | + foreach ($this->trashManager->listTrashRoot($this->user) as $trashItem) { |
|
| 54 | + $this->trashManager->removeItem($trashItem); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function getName(): string { |
|
| 59 | + return 'trash'; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function setName($name) { |
|
| 63 | + throw new Forbidden('Permission denied to rename this trashbin'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function createFile($name, $data = null) { |
|
| 67 | + throw new Forbidden('Not allowed to create files in the trashbin'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function createDirectory($name) { |
|
| 71 | + throw new Forbidden('Not allowed to create folders in the trashbin'); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public function getChildren(): array { |
|
| 75 | + $entries = $this->trashManager->listTrashRoot($this->user); |
|
| 76 | + |
|
| 77 | + $children = array_map(function (ITrashItem $entry) { |
|
| 78 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 79 | + return new TrashFolder($this->trashManager, $entry); |
|
| 80 | + } |
|
| 81 | + return new TrashFile($this->trashManager, $entry); |
|
| 82 | + }, $entries); |
|
| 83 | + |
|
| 84 | + return $children; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function getChild($name): ITrash { |
|
| 88 | + $entries = $this->getChildren(); |
|
| 89 | + |
|
| 90 | + foreach ($entries as $entry) { |
|
| 91 | + if ($entry->getName() === $name) { |
|
| 92 | + return $entry; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + throw new NotFound(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function childExists($name): bool { |
|
| 100 | + try { |
|
| 101 | + $this->getChild($name); |
|
| 102 | + return true; |
|
| 103 | + } catch (NotFound $e) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getLastModified(): int { |
|
| 109 | + return 0; |
|
| 110 | + } |
|
| 111 | 111 | } |