Skip to content

Commit d62f71d

Browse files
authored
Merge pull request #62651 from nextcloud/carl/trashbackend
feat(trash): Add getTrashRootItem to ITrashBackend
2 parents ee0b6e9 + c59751f commit d62f71d

4 files changed

Lines changed: 13 additions & 33 deletions

File tree

‎apps/files_trashbin/lib/Trash/ITrashBackend.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function listTrashRoot(IUser $user): array;
3535
*/
3636
public function listTrashFolder(ITrashItem $folder): array;
3737

38+
/**
39+
* Get a specific item in the root of the trashbin
40+
*
41+
* @param IUser $user
42+
* @return ?ITrashItem
43+
* @since 36.0.0
44+
*/
45+
public function getTrashRootItem(IUser $user, string $name): ?ITrashItem;
46+
3847
/**
3948
* Restore a trashbin item
4049
*

‎apps/files_trashbin/lib/Trash/ITrashManager.php‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
namespace OCA\Files_Trashbin\Trash;
1111

12-
use OCP\IUser;
13-
1412
interface ITrashManager extends ITrashBackend {
1513
/**
1614
* Add a backend for the trashbin
@@ -21,25 +19,6 @@ interface ITrashManager extends ITrashBackend {
2119
*/
2220
public function registerBackend(string $storageType, ITrashBackend $backend);
2321

24-
/**
25-
* List all trash items in the root of the trashbin
26-
*
27-
* @param IUser $user
28-
* @return ITrashItem[]
29-
* @since 15.0.0
30-
*/
31-
#[\Override]
32-
public function listTrashRoot(IUser $user): array;
33-
34-
/**
35-
* Get a specific item in the root of the trashbin
36-
*
37-
* @param IUser $user
38-
* @return ?ITrashItem
39-
* @since 35.0.0
40-
*/
41-
public function getTrashRootItem(IUser $user, string $name): ?ITrashItem;
42-
4322
/**
4423
* Temporally prevent files from being moved to the trash
4524
*

‎apps/files_trashbin/lib/Trash/LegacyTrashBackend.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function listTrashRoot(IUser $user): array {
6161
return array_map(fn (FileInfo $fileInfo): ITrashItem => $this->mapTrashItem($fileInfo, $user), $entries);
6262
}
6363

64+
#[\Override]
6465
public function getTrashRootItem(IUser $user, string $name): ?ITrashItem {
6566
$entry = Helper::getTrashFile('/', $user->getUID(), $name);
6667
if ($entry === null) {

‎apps/files_trashbin/lib/Trash/TrashManager.php‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,9 @@ public function listTrashRoot(IUser $user): array {
4242
#[\Override]
4343
public function getTrashRootItem(IUser $user, string $name): ?ITrashItem {
4444
foreach ($this->getBackends() as $backend) {
45-
if (method_exists($backend, 'getTrashRootItem')) {
46-
$item = $backend->getTrashRootItem($user, $name);
47-
if ($item !== null) {
48-
return $item;
49-
}
50-
} else {
51-
$items = $backend->listTrashRoot($user);
52-
foreach ($items as $item) {
53-
if ($item->getName() === $name) {
54-
return $item;
55-
}
56-
}
45+
$item = $backend->getTrashRootItem($user, $name);
46+
if ($item !== null) {
47+
return $item;
5748
}
5849
}
5950
return null;

0 commit comments

Comments
 (0)