Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Decouple from groupfolders app & remove PSALM warnings
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
R0Wi authored and backportbot-nextcloud[bot] committed Sep 22, 2023
commit f5d0264296616d2dc9975e3deb1acc08dec8ca0a
31 changes: 18 additions & 13 deletions apps/files_trashbin/lib/Command/RestoreAllFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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');
Expand Down Expand Up @@ -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("<error>Unknown user $uid</error>");
return;
}

$userTrashItems = $this->filterTrashItems(
$this->trashManager->listTrashRoot($user),
$scope,
Expand Down Expand Up @@ -215,7 +216,7 @@ protected function restoreDeletedFiles(string $uid, int $scope, ?int $restoreFro
$count = $count + 1;
$output->writeln(" <info>success</info>");
}

if (!$dryRun) {
$output->writeln("Successfully restored <info>$count</info> out of <info>$trashCount</info> files.");
}
Expand Down Expand Up @@ -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
Expand All @@ -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 <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;
}
Expand All @@ -301,7 +306,7 @@ protected function filterTrashItems(array $trashItems, int $scope, ?int $restore
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted after the restore-to timestamp", OutputInterface::VERBOSITY_VERBOSE);
continue;
}

$filteredTrashItems[] = $trashItem;
}
return $filteredTrashItems;
Expand Down
6 changes: 6 additions & 0 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,12 @@
<code><![CDATA[isset($_['hideFileList']) && $_['hideFileList'] !== true]]></code>
</RedundantCondition>
</file>
<file src="apps/files_trashbin/lib/Command/RestoreAllFiles.php">
<RedundantCondition>
<code><![CDATA[$scope === self::SCOPE_GROUPFOLDERS && $trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem']]></code>
<code><![CDATA[$trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem']]></code>
</RedundantCondition>
</file>
<file src="apps/files_trashbin/lib/Listeners/LoadAdditionalScripts.php">
<MissingTemplateParam>
<code>IEventListener</code>
Expand Down