aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRobin Windey <ro.windey@gmail.com>2023-08-12 13:06:34 +0000
committerRobin Windey <ro.windey@gmail.com>2023-08-18 07:25:39 +0200
commitee66518ca25c53836a9b8a6eb3c17d46e3be8251 (patch)
treed34e0939be908b51844cc717d28046ea7d4ebb40 /apps
parent98dd02b4674c095801ab32c70261597bca905814 (diff)
downloadnextcloud-server-ee66518ca25c53836a9b8a6eb3c17d46e3be8251.tar.gz
nextcloud-server-ee66518ca25c53836a9b8a6eb3c17d46e3be8251.zip
Decouple from groupfolders app & remove PSALM warnings
Signed-off-by: GitHub <noreply@github.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_trashbin/lib/Command/RestoreAllFiles.php31
1 files changed, 18 insertions, 13 deletions
diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
index 98dc88db870..1e852c3658e 100644
--- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php
+++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
@@ -124,13 +124,8 @@ class RestoreAllFiles extends Base {
if (!empty($users)) {
foreach ($users as $user) {
- if ($this->userManager->userExists($user)) {
- $output->writeln("Restoring deleted files for user <info>$user</info>");
- $this->restoreDeletedFiles($user, $scope, $restoreFrom, $restoreTo, $dryRun, $output);
- } else {
- $output->writeln("<error>Unknown user $user</error>");
- return 1;
- }
+ $output->writeln("Restoring deleted files for user <info>$user</info>");
+ $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 @@ class RestoreAllFiles extends Base {
\OC_User::setUserId($uid);
$user = $this->userManager->get($uid);
+
+ if ($user === null) {
+ $output->writeln("<error>Unknown user $uid</error>");
+ return;
+ }
+
$userTrashItems = $this->filterTrashItems(
$this->trashManager->listTrashRoot($user),
$scope,
@@ -215,7 +216,7 @@ class RestoreAllFiles extends Base {
$count = $count + 1;
$output->writeln(" <info>success</info>");
}
-
+
if (!$dryRun) {
$output->writeln("Successfully restored <info>$count</info> out of <info>$trashCount</info> files.");
}
@@ -270,7 +271,7 @@ class RestoreAllFiles extends Base {
}
/**
- * @param ITrashItem[] $trashItem
+ * @param ITrashItem[] $trashItems
* @param int $scope
* @param int|null $restoreFrom
* @param int|null $restoreTo
@@ -280,12 +281,16 @@ class RestoreAllFiles extends Base {
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 <info>" . $trashItem->getName() . "</info> 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 <info>" . $trashItem->getName() . "</info> because it is not a groupfolders trash item", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
@@ -301,7 +306,7 @@ class RestoreAllFiles extends Base {
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted after the restore-to timestamp", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
-
+
$filteredTrashItems[] = $trashItem;
}
return $filteredTrashItems;