aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Trash
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-09-19 19:00:58 +0200
committerRobin Appelman <robin@icewind.nl>2018-10-17 14:56:48 +0200
commitd38163e89574e9d2a12be0cdf8f72e1e9bb4b75f (patch)
treebc07f70d769ed6a1e654b236b51c8499a1bc787c /apps/files_trashbin/lib/Trash
parent4adac445dc57d1ccc7f26e21018e1e731e5b1654 (diff)
downloadnextcloud-server-d38163e89574e9d2a12be0cdf8f72e1e9bb4b75f.tar.gz
nextcloud-server-d38163e89574e9d2a12be0cdf8f72e1e9bb4b75f.zip
fix trashbin previews for modular api
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.php12
-rw-r--r--apps/files_trashbin/lib/Trash/LegacyTrashBackend.php25
-rw-r--r--apps/files_trashbin/lib/Trash/TrashManager.php16
3 files changed, 47 insertions, 6 deletions
diff --git a/apps/files_trashbin/lib/Trash/ITrashBackend.php b/apps/files_trashbin/lib/Trash/ITrashBackend.php
index 35b16a00c22..90d3a29613d 100644
--- a/apps/files_trashbin/lib/Trash/ITrashBackend.php
+++ b/apps/files_trashbin/lib/Trash/ITrashBackend.php
@@ -22,6 +22,8 @@
namespace OCA\Files_Trashbin\Trash;
use OCP\Files\FileInfo;
+use OCP\Files\Node;
+use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
@@ -61,7 +63,6 @@ interface ITrashBackend {
*
* @param IUser $user
* @param ITrashItem $item
- * @return
* @since 15.0.0
*/
public function removeItem(IUser $user, ITrashItem $item);
@@ -74,5 +75,12 @@ interface ITrashBackend {
* @return boolean whether or not the file was moved to trash, if false then the file should be deleted normally
* @since 15.0.0
*/
- public function moveToTrash(IStorage $storage, string $internalPath);
+ public function moveToTrash(IStorage $storage, string $internalPath): bool;
+
+ /**
+ * @param IUser $user
+ * @param int $fileId
+ * @return Node|null
+ */
+ public function getTrashNodeById(IUser $user, int $fileId);
}
diff --git a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
index 210c84228f7..04e3b284775 100644
--- a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
+++ b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
@@ -27,6 +27,8 @@ use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Storage;
use OCA\Files_Trashbin\Trashbin;
use OCP\Files\FileInfo;
+use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
@@ -34,6 +36,13 @@ class LegacyTrashBackend implements ITrashBackend {
/** @var array */
private $deletedFiles = [];
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ public function __construct(IRootFolder $rootFolder) {
+ $this->rootFolder = $rootFolder;
+ }
+
/**
* @param array $items
* @param IUser $user
@@ -78,7 +87,7 @@ class LegacyTrashBackend implements ITrashBackend {
}
- public function moveToTrash(IStorage $storage, string $internalPath) {
+ public function moveToTrash(IStorage $storage, string $internalPath): bool {
if (!$storage instanceof Storage) {
return false;
}
@@ -99,4 +108,18 @@ class LegacyTrashBackend implements ITrashBackend {
return $result;
}
+
+ public function getTrashNodeById(IUser $user, int $fileId) {
+ try {
+ $userFolder = $this->rootFolder->getUserFolder($user->getUID());
+ $trash = $userFolder->getParent()->get('files_trashbin/files');
+ $trashFiles = $trash->getById($fileId);
+ if (!$trashFiles) {
+ return null;
+ }
+ return $trashFiles ? array_pop($trashFiles) : null;
+ } catch (NotFoundException $e) {
+ return null;
+ }
+ }
}
diff --git a/apps/files_trashbin/lib/Trash/TrashManager.php b/apps/files_trashbin/lib/Trash/TrashManager.php
index 3870271cc7e..cae4f2473ad 100644
--- a/apps/files_trashbin/lib/Trash/TrashManager.php
+++ b/apps/files_trashbin/lib/Trash/TrashManager.php
@@ -76,9 +76,9 @@ class TrashManager implements ITrashManager {
*/
public function getBackendForStorage(IStorage $storage): ITrashBackend {
$fullType = get_class($storage);
- $foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($fullType) {
+ $foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($storage) {
if (
- is_subclass_of($fullType, $registeredType) &&
+ $storage->instanceOfStorage($registeredType) &&
($type === '' || is_subclass_of($registeredType, $type))
) {
return $registeredType;
@@ -93,7 +93,7 @@ class TrashManager implements ITrashManager {
}
}
- public function moveToTrash(IStorage $storage, string $internalPath) {
+ public function moveToTrash(IStorage $storage, string $internalPath): bool {
if ($this->trashPaused) {
return false;
}
@@ -105,6 +105,16 @@ class TrashManager implements ITrashManager {
}
}
+ public function getTrashNodeById(IUser $user, int $fileId) {
+ foreach ($this->backends as $backend) {
+ $item = $backend->getTrashNodeById($user, $fileId);
+ if ($item !== null) {
+ return $item;
+ }
+ }
+ return null;
+ }
+
public function pauseTrash() {
$this->trashPaused = true;
}