From 78ec36f2acbf963052a3469822f1a821ed9f8004 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 8 Aug 2025 09:04:10 +0200 Subject: [PATCH 1/2] feat(trashbin): Implement ITrashBackend::getTrashRootsForUser Signed-off-by: Carl Schwan --- lib/AppInfo/Application.php | 1 + lib/Trash/TrashBackend.php | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 8db671213..97e709336 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -136,6 +136,7 @@ public function register(IRegistrationContext $context): void { $c->get(MountProvider::class), $c->get(IMountManager::class), $c->get(IStorageFactory::class), + $c->get(IDBConnection::class), ); $hasVersionApp = interface_exists(\OCA\Files_Versions\Versions\IVersionBackend::class); if ($hasVersionApp) { diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php index a16549aea..fcbc6b5d3 100644 --- a/lib/Trash/TrashBackend.php +++ b/lib/Trash/TrashBackend.php @@ -9,6 +9,7 @@ namespace OCA\GroupFolders\Trash; use OC\Encryption\Exceptions\DecryptionFailedException; +use OC\Files\Node\LazyFolder; use OC\Files\Storage\Wrapper\Encryption; use OC\Files\Storage\Wrapper\Jail; use OCA\Files_Trashbin\Expiration; @@ -34,6 +35,7 @@ use OCP\Files\Storage\ISharedStorage; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; +use OCP\IDBConnection; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -54,6 +56,7 @@ public function __construct( private readonly MountProvider $mountProvider, private readonly IMountManager $mountManager, private readonly IStorageFactory $storageFactory, + private readonly IDBConnection $connection, ) { } @@ -629,8 +632,7 @@ public function expire(Expiration $expiration): array { } /** - * @param array $existingFolders - * Cleanup trashbin of of group folders that have been deleted + * @param array $existingFolders Cleanup trashbin of group folders that have been deleted */ private function cleanupDeletedFoldersTrash(array $existingFolders): void { $trashRoot = $this->getTrashRoot(); @@ -645,4 +647,30 @@ private function cleanupDeletedFoldersTrash(array $existingFolders): void { } } } + + public function getTrashRootsForUser(IUser $user): array { + $folders = $this->folderManager->getFoldersForUser($user); + + return array_filter(array_map(function (FolderDefinitionWithPermissions $folder) use ($user): ?Folder { + $qb = $this->connection->getQueryBuilder(); + $qb->select('fileid', 'storage') + ->from('filecache') + ->hintShardKey('storage', $folder->storageId) + ->where($qb->expr()->eq('path_hash', $qb->createNamedParameter(md5('__groupfolders/trash/' . $folder->id)))); + $result = $qb->executeQuery()->fetchAll(); + + if (!$result || !count($result)) { + return null; + } + + return new LazyFolder( + $this->rootFolder, + fn () => $this->setupTrashFolder($folder), + [ + 'fileid' => $result[0]['fileid'], + 'mountpoint_numericStorageId' => $result[0]['storage'], + ] + ); + }, $folders), fn ($folder) => $folder !== null); + } } From 1a752ae17554dde49baf8e511580f8422f127f49 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 4 Feb 2026 12:55:35 +0100 Subject: [PATCH 2/2] refactor: Use more strict comparaison Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> Signed-off-by: Carl Schwan --- lib/Trash/TrashBackend.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php index fcbc6b5d3..9e053b8a5 100644 --- a/lib/Trash/TrashBackend.php +++ b/lib/Trash/TrashBackend.php @@ -659,7 +659,7 @@ public function getTrashRootsForUser(IUser $user): array { ->where($qb->expr()->eq('path_hash', $qb->createNamedParameter(md5('__groupfolders/trash/' . $folder->id)))); $result = $qb->executeQuery()->fetchAll(); - if (!$result || !count($result)) { + if ($result === false || $result === []) { return null; } @@ -671,6 +671,6 @@ public function getTrashRootsForUser(IUser $user): array { 'mountpoint_numericStorageId' => $result[0]['storage'], ] ); - }, $folders), fn ($folder) => $folder !== null); + }, $folders), static fn ($folder) => $folder !== null); } }