diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
index 98dc88db8708f..1e852c3658ee2 100644
--- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php
+++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
@@ -124,13 +124,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!empty($users)) {
foreach ($users as $user) {
- if ($this->userManager->userExists($user)) {
- $output->writeln("Restoring deleted files for user $user");
- $this->restoreDeletedFiles($user, $scope, $restoreFrom, $restoreTo, $dryRun, $output);
- } else {
- $output->writeln("Unknown user $user");
- return 1;
- }
+ $output->writeln("Restoring deleted files for user $user");
+ $this->restoreDeletedFiles($user, $scope, $restoreFrom, $restoreTo, $dryRun, $output);
}
} elseif ($input->getOption('all-users')) {
$output->writeln('Restoring deleted files for all users');
@@ -173,6 +168,12 @@ protected function restoreDeletedFiles(string $uid, int $scope, ?int $restoreFro
\OC_User::setUserId($uid);
$user = $this->userManager->get($uid);
+
+ if ($user === null) {
+ $output->writeln("Unknown user $uid");
+ return;
+ }
+
$userTrashItems = $this->filterTrashItems(
$this->trashManager->listTrashRoot($user),
$scope,
@@ -215,7 +216,7 @@ protected function restoreDeletedFiles(string $uid, int $scope, ?int $restoreFro
$count = $count + 1;
$output->writeln(" success");
}
-
+
if (!$dryRun) {
$output->writeln("Successfully restored $count out of $trashCount files.");
}
@@ -270,7 +271,7 @@ protected function parseTimestamp(?string $timestamp): ?int {
}
/**
- * @param ITrashItem[] $trashItem
+ * @param ITrashItem[] $trashItems
* @param int $scope
* @param int|null $restoreFrom
* @param int|null $restoreTo
@@ -280,12 +281,16 @@ protected function parseTimestamp(?string $timestamp): ?int {
protected function filterTrashItems(array $trashItems, int $scope, ?int $restoreFrom, ?int $restoreTo, OutputInterface $output): array {
$filteredTrashItems = [];
foreach ($trashItems as $trashItem) {
- // Check scope with exact class names
- if ($scope === self::SCOPE_USER && get_class($trashItem) !== \OCA\Files_Trashbin\Trash\TrashItem::class) {
+ $trashItemClass = get_class($trashItem);
+
+ // Check scope with exact class name for locally deleted files
+ if ($scope === self::SCOPE_USER && $trashItemClass !== \OCA\Files_Trashbin\Trash\TrashItem::class) {
$output->writeln("Skipping " . $trashItem->getName() . " because it is not a user trash item", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
- if ($scope === self::SCOPE_GROUPFOLDERS && get_class($trashItem) !== \OCA\GroupFolders\Trash\GroupTrashItem::class) {
+
+ // Check scope for groupfolders by string because the groupfolders app might not be installed
+ if ($scope === self::SCOPE_GROUPFOLDERS && $trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem') {
$output->writeln("Skipping " . $trashItem->getName() . " because it is not a groupfolders trash item", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
@@ -301,7 +306,7 @@ protected function filterTrashItems(array $trashItems, int $scope, ?int $restore
$output->writeln("Skipping " . $trashItem->getName() . " because it was deleted after the restore-to timestamp", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
-
+
$filteredTrashItems[] = $trashItem;
}
return $filteredTrashItems;
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 3d56f710237c1..bc88ef086df3c 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -1305,6 +1305,12 @@
+
+
+
+
+
+
IEventListener