Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 30 additions & 2 deletions lib/Trash/TrashBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -54,6 +56,7 @@ public function __construct(
private readonly MountProvider $mountProvider,
private readonly IMountManager $mountManager,
private readonly IStorageFactory $storageFactory,
private readonly IDBConnection $connection,
) {
}

Expand Down Expand Up @@ -629,8 +632,7 @@ public function expire(Expiration $expiration): array {
}

/**
* @param array<int, FolderDefinitionWithPermissions> $existingFolders
* Cleanup trashbin of of group folders that have been deleted
* @param array<int, FolderDefinitionWithPermissions> $existingFolders Cleanup trashbin of group folders that have been deleted
*/
private function cleanupDeletedFoldersTrash(array $existingFolders): void {
$trashRoot = $this->getTrashRoot();
Expand All @@ -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))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this actually works with the new storage layout.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I need to test that with the new code

$result = $qb->executeQuery()->fetchAll();

if ($result === false || $result === []) {
return null;
}

return new LazyFolder(
$this->rootFolder,
fn () => $this->setupTrashFolder($folder),
[
'fileid' => $result[0]['fileid'],
'mountpoint_numericStorageId' => $result[0]['storage'],
]
);
}, $folders), static fn ($folder) => $folder !== null);
}
}