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); + } }