diff options
author | Robin Appelman <robin@icewind.nl> | 2018-10-17 15:21:09 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-10-17 15:21:09 +0200 |
commit | 9e0ebf183044f00d7e1e3b30c9a01e84d051dd78 (patch) | |
tree | cf1fc3ded8817bd23ed99cda3af658f58b057e8c /apps/files_trashbin/lib/Trash | |
parent | 136113a22b2cc02a86a343d55eb0ce38b3dc6bbd (diff) | |
download | nextcloud-server-9e0ebf183044f00d7e1e3b30c9a01e84d051dd78.tar.gz nextcloud-server-9e0ebf183044f00d7e1e3b30c9a01e84d051dd78.zip |
store user for trashitem in the trashitem
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_trashbin/lib/Trash')
-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 |
5 files changed, 40 insertions, 46 deletions
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); } /** |