Skip to content

Commit d2581e5

Browse files
authored
Decouple from groupfolders app & remove PSALM warnings
Signed-off-by: GitHub <noreply@github.com>
1 parent e3d2461 commit d2581e5

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

apps/files_trashbin/lib/Command/RestoreAllFiles.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
124124

125125
if (!empty($users)) {
126126
foreach ($users as $user) {
127-
if ($this->userManager->userExists($user)) {
128-
$output->writeln("Restoring deleted files for user <info>$user</info>");
129-
$this->restoreDeletedFiles($user, $scope, $restoreFrom, $restoreTo, $dryRun, $output);
130-
} else {
131-
$output->writeln("<error>Unknown user $user</error>");
132-
return 1;
133-
}
127+
$output->writeln("Restoring deleted files for user <info>$user</info>");
128+
$this->restoreDeletedFiles($user, $scope, $restoreFrom, $restoreTo, $dryRun, $output);
134129
}
135130
} elseif ($input->getOption('all-users')) {
136131
$output->writeln('Restoring deleted files for all users');
@@ -173,6 +168,12 @@ protected function restoreDeletedFiles(string $uid, int $scope, ?int $restoreFro
173168
\OC_User::setUserId($uid);
174169

175170
$user = $this->userManager->get($uid);
171+
172+
if ($user === null) {
173+
$output->writeln("<error>Unknown user $uid</error>");
174+
return;
175+
}
176+
176177
$userTrashItems = $this->filterTrashItems(
177178
$this->trashManager->listTrashRoot($user),
178179
$scope,
@@ -215,7 +216,7 @@ protected function restoreDeletedFiles(string $uid, int $scope, ?int $restoreFro
215216
$count = $count + 1;
216217
$output->writeln(" <info>success</info>");
217218
}
218-
219+
219220
if (!$dryRun) {
220221
$output->writeln("Successfully restored <info>$count</info> out of <info>$trashCount</info> files.");
221222
}
@@ -270,7 +271,7 @@ protected function parseTimestamp(?string $timestamp): ?int {
270271
}
271272

272273
/**
273-
* @param ITrashItem[] $trashItem
274+
* @param ITrashItem[] $trashItems
274275
* @param int $scope
275276
* @param int|null $restoreFrom
276277
* @param int|null $restoreTo
@@ -280,12 +281,16 @@ protected function parseTimestamp(?string $timestamp): ?int {
280281
protected function filterTrashItems(array $trashItems, int $scope, ?int $restoreFrom, ?int $restoreTo, OutputInterface $output): array {
281282
$filteredTrashItems = [];
282283
foreach ($trashItems as $trashItem) {
283-
// Check scope with exact class names
284-
if ($scope === self::SCOPE_USER && get_class($trashItem) !== \OCA\Files_Trashbin\Trash\TrashItem::class) {
284+
$trashItemClass = get_class($trashItem);
285+
286+
// Check scope with exact class name for locally deleted files
287+
if ($scope === self::SCOPE_USER && $trashItemClass !== \OCA\Files_Trashbin\Trash\TrashItem::class) {
285288
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it is not a user trash item", OutputInterface::VERBOSITY_VERBOSE);
286289
continue;
287290
}
288-
if ($scope === self::SCOPE_GROUPFOLDERS && get_class($trashItem) !== \OCA\GroupFolders\Trash\GroupTrashItem::class) {
291+
292+
// Check scope for groupfolders by string because the groupfolders app might not be installed
293+
if ($scope === self::SCOPE_GROUPFOLDERS && $trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem') {
289294
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it is not a groupfolders trash item", OutputInterface::VERBOSITY_VERBOSE);
290295
continue;
291296
}
@@ -301,7 +306,7 @@ protected function filterTrashItems(array $trashItems, int $scope, ?int $restore
301306
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted after the restore-to timestamp", OutputInterface::VERBOSITY_VERBOSE);
302307
continue;
303308
}
304-
309+
305310
$filteredTrashItems[] = $trashItem;
306311
}
307312
return $filteredTrashItems;

build/psalm-baseline.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,12 @@
13051305
<code><![CDATA[isset($_['hideFileList']) && $_['hideFileList'] !== true]]></code>
13061306
</RedundantCondition>
13071307
</file>
1308+
<file src="apps/files_trashbin/lib/Command/RestoreAllFiles.php">
1309+
<RedundantCondition>
1310+
<code><![CDATA[$scope === self::SCOPE_GROUPFOLDERS && $trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem']]></code>
1311+
<code><![CDATA[$trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem']]></code>
1312+
</RedundantCondition>
1313+
</file>
13081314
<file src="apps/files_trashbin/lib/Listeners/LoadAdditionalScripts.php">
13091315
<MissingTemplateParam>
13101316
<code>IEventListener</code>

0 commit comments

Comments
 (0)