diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_trashbin/lib/Sabre/AbstractTrash.php | 10 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php | 6 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/RestoreFolder.php | 8 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/TrashHome.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/TrashRoot.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trash/ITrashBackend.php | 6 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trash/ITrashItem.php | 8 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trash/LegacyTrashBackend.php | 17 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trash/TrashItem.php | 47 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trash/TrashManager.php | 8 |
10 files changed, 50 insertions, 68 deletions
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrash.php b/apps/files_trashbin/lib/Sabre/AbstractTrash.php index 5d4b19513a4..b4d13a41e38 100644 --- a/apps/files_trashbin/lib/Sabre/AbstractTrash.php +++ b/apps/files_trashbin/lib/Sabre/AbstractTrash.php @@ -34,12 +34,8 @@ abstract class AbstractTrash implements ITrash { /** @var ITrashManager */ protected $trashManager; - /** @var IUser */ - protected $user; - - public function __construct(ITrashManager $trashManager, IUser $user, ITrashItem $data) { + public function __construct(ITrashManager $trashManager, ITrashItem $data) { $this->trashManager = $trashManager; - $this->user = $user; $this->data = $data; } @@ -80,11 +76,11 @@ abstract class AbstractTrash implements ITrash { } public function getOriginalLocation(): string { - return $this->data->getOriginalLocation($this->user); + return $this->data->getOriginalLocation(); } public function delete() { - $this->trashManager->removeItem($this->user, $this->data); + $this->trashManager->removeItem($this->data); } public function restore(): bool { diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php index 19a6ba2d3fb..dd45dbd5c8c 100644 --- a/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php +++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php @@ -30,13 +30,13 @@ use Sabre\DAV\ICollection; abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash { public function getChildren(): array { - $entries = $this->trashManager->listTrashFolder($this->user, $this->data); + $entries = $this->trashManager->listTrashFolder($this->data); $children = array_map(function (ITrashItem $entry) { if ($entry->getType() === FileInfo::TYPE_FOLDER) { - return new TrashFolderFolder($this->trashManager, $this->user, $entry); + return new TrashFolderFolder($this->trashManager, $entry); } - return new TrashFolderFile($this->trashManager, $this->user, $entry); + return new TrashFolderFile($this->trashManager, $entry); }, $entries); return $children; diff --git a/apps/files_trashbin/lib/Sabre/RestoreFolder.php b/apps/files_trashbin/lib/Sabre/RestoreFolder.php index 04f23db0ed4..177064dbb48 100644 --- a/apps/files_trashbin/lib/Sabre/RestoreFolder.php +++ b/apps/files_trashbin/lib/Sabre/RestoreFolder.php @@ -31,14 +31,6 @@ use Sabre\DAV\INode; class RestoreFolder implements ICollection, IMoveTarget { - - /** @var string */ - protected $userId; - - public function __construct(string $userId) { - $this->userId = $userId; - } - public function createFile($name, $data = null) { throw new Forbidden(); } diff --git a/apps/files_trashbin/lib/Sabre/TrashHome.php b/apps/files_trashbin/lib/Sabre/TrashHome.php index 416b88635a4..12c2578bc3b 100644 --- a/apps/files_trashbin/lib/Sabre/TrashHome.php +++ b/apps/files_trashbin/lib/Sabre/TrashHome.php @@ -73,7 +73,7 @@ class TrashHome implements ICollection { public function getChild($name) { if ($name === 'restore') { - return new RestoreFolder($this->user->getUID()); + return new RestoreFolder(); } if ($name === 'trash') { return new TrashRoot($this->user, $this->trashManager); @@ -84,7 +84,7 @@ class TrashHome implements ICollection { public function getChildren(): array { return [ - new RestoreFolder($this->user->getUID()), + new RestoreFolder(), new TrashRoot($this->user, $this->trashManager) ]; } diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php index 57cfe2b2dff..45f27f48b17 100644 --- a/apps/files_trashbin/lib/Sabre/TrashRoot.php +++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php @@ -69,9 +69,9 @@ class TrashRoot implements ICollection { $children = array_map(function (ITrashItem $entry) { if ($entry->getType() === FileInfo::TYPE_FOLDER) { - return new TrashFolder($this->trashManager, $this->user, $entry); + return new TrashFolder($this->trashManager, $entry); } - return new TrashFile($this->trashManager, $this->user, $entry); + return new TrashFile($this->trashManager, $entry); }, $entries); return $children; diff --git a/apps/files_trashbin/lib/Trash/ITrashBackend.php b/apps/files_trashbin/lib/Trash/ITrashBackend.php index 90d3a29613d..ebdf9720d7c 100644 --- a/apps/files_trashbin/lib/Trash/ITrashBackend.php +++ b/apps/files_trashbin/lib/Trash/ITrashBackend.php @@ -43,12 +43,11 @@ interface ITrashBackend { /** * List all trash items in a subfolder in the trashbin * - * @param IUser $user * @param ITrashItem $folder * @return ITrashItem[] * @since 15.0.0 */ - public function listTrashFolder(IUser $user, ITrashItem $folder): array; + public function listTrashFolder(ITrashItem $folder): array; /** * Restore a trashbin item @@ -61,11 +60,10 @@ interface ITrashBackend { /** * Permanently remove an item from trash * - * @param IUser $user * @param ITrashItem $item * @since 15.0.0 */ - public function removeItem(IUser $user, ITrashItem $item); + public function removeItem(ITrashItem $item); /** * Move a file or folder to trash diff --git a/apps/files_trashbin/lib/Trash/ITrashItem.php b/apps/files_trashbin/lib/Trash/ITrashItem.php index 75e0f410301..74348cf1817 100644 --- a/apps/files_trashbin/lib/Trash/ITrashItem.php +++ b/apps/files_trashbin/lib/Trash/ITrashItem.php @@ -67,4 +67,12 @@ interface ITrashItem extends FileInfo { * @since 15.0.0 */ public function isRootItem(): bool; + + /** + * Get the user for which this trash item applies + * + * @return IUser + * @since 15.0.0 + */ + public function getUser(): IUser; } diff --git a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php index 2c0d19afebf..b8519fa27cc 100644 --- a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php +++ b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php @@ -49,35 +49,38 @@ class LegacyTrashBackend implements ITrashBackend { * @param ITrashItem $parent * @return ITrashItem[] */ - private function mapTrashItems(array $items, ITrashItem $parent = null): array { + private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array { $parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : ''; $isRoot = $parent === null; - return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot) { + return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) { return new TrashItem( $this, $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName(), $file->getMTime(), $parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''), - $file + $file, + $user ); }, $items); } public function listTrashRoot(IUser $user): array { $entries = Helper::getTrashFiles('/', $user->getUID()); - return $this->mapTrashItems($entries); + return $this->mapTrashItems($entries, $user); } - public function listTrashFolder(IUser $user, ITrashItem $folder): array { + public function listTrashFolder(ITrashItem $folder): array { + $user = $folder->getUser(); $entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID()); - return $this->mapTrashItems($entries, $folder); + return $this->mapTrashItems($entries, $user ,$folder); } public function restoreItem(ITrashItem $item) { Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null); } - public function removeItem(IUser $user, ITrashItem $item) { + public function removeItem(ITrashItem $item) { + $user = $item->getUser(); if ($item->isRootItem()) { $path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime())); Trashbin::delete($path, $user->getUID(), $item->getDeletedTime()); diff --git a/apps/files_trashbin/lib/Trash/TrashItem.php b/apps/files_trashbin/lib/Trash/TrashItem.php index 880a5503014..cd7079bcf26 100644 --- a/apps/files_trashbin/lib/Trash/TrashItem.php +++ b/apps/files_trashbin/lib/Trash/TrashItem.php @@ -35,22 +35,23 @@ class TrashItem implements ITrashItem { private $trashPath; /** @var FileInfo */ private $fileInfo; - - /** - * TrashItem constructor. - * - * @param ITrashBackend $backend - * @param string $originalLocation - * @param int $deletedTime - * @param string $trashPath - * @param FileInfo $fileInfo - */ - public function __construct(ITrashBackend $backend, string $originalLocation, int $deletedTime, string $trashPath, FileInfo $fileInfo) { + /** @var IUser */ + private $user; + + public function __construct( + ITrashBackend $backend, + string $originalLocation, + int $deletedTime, + string $trashPath, + FileInfo $fileInfo, + IUser $user + ) { $this->backend = $backend; $this->orignalLocation = $originalLocation; $this->deletedTime = $deletedTime; $this->trashPath = $trashPath; $this->fileInfo = $fileInfo; + $this->user = $user; } public function getTrashBackend(): ITrashBackend { @@ -73,6 +74,10 @@ class TrashItem implements ITrashItem { return substr_count($this->getTrashPath(), '/') === 1; } + public function getUser(): IUser { + return $this->user; + } + public function getEtag() { return $this->fileInfo->getEtag(); } @@ -93,95 +98,75 @@ class TrashItem implements ITrashItem { return $this->fileInfo->getInternalPath(); } - public function getPath() { return $this->fileInfo->getPath(); } - public function getMimetype() { return $this->fileInfo->getMimetype(); } - public function getMimePart() { return $this->fileInfo->getMimePart(); } - public function getStorage() { return $this->fileInfo->getStorage(); } - public function getId() { return $this->fileInfo->getId(); } - public function isEncrypted() { return $this->fileInfo->isEncrypted(); } - public function getPermissions() { return $this->fileInfo->getPermissions(); } - public function getType() { return $this->fileInfo->getType(); } - public function isReadable() { return $this->fileInfo->isReadable(); } - public function isUpdateable() { return $this->fileInfo->isUpdateable(); } - public function isCreatable() { return $this->fileInfo->isCreatable(); } - public function isDeletable() { return $this->fileInfo->isDeletable(); } - public function isShareable() { return $this->fileInfo->isShareable(); } - public function isShared() { return $this->fileInfo->isShared(); } - public function isMounted() { return $this->fileInfo->isMounted(); } - public function getMountPoint() { return $this->fileInfo->getMountPoint(); } - public function getOwner() { return $this->fileInfo->getOwner(); } - public function getChecksum() { return $this->fileInfo->getChecksum(); } - - } diff --git a/apps/files_trashbin/lib/Trash/TrashManager.php b/apps/files_trashbin/lib/Trash/TrashManager.php index cae4f2473ad..50ab539c210 100644 --- a/apps/files_trashbin/lib/Trash/TrashManager.php +++ b/apps/files_trashbin/lib/Trash/TrashManager.php @@ -57,16 +57,16 @@ class TrashManager implements ITrashManager { return $item->getTrashBackend(); } - public function listTrashFolder(IUser $user, ITrashItem $folder): array { - return $this->getBackendForItem($folder)->listTrashFolder($user, $folder); + public function listTrashFolder(ITrashItem $folder): array { + return $this->getBackendForItem($folder)->listTrashFolder($folder); } public function restoreItem(ITrashItem $item) { return $this->getBackendForItem($item)->restoreItem($item); } - public function removeItem(IUser $user, ITrashItem $item) { - $this->getBackendForItem($item)->removeItem($user, $item); + public function removeItem(ITrashItem $item) { + $this->getBackendForItem($item)->removeItem($item); } /** |