summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-12-16 17:20:40 +0100
committerGitHub <noreply@github.com>2022-12-16 17:20:40 +0100
commit4f2923862ad7d499684571ded196f2d2fc85344a (patch)
tree8e7b729f5b25e5fd6c1cefb991c678a5d59b12ea
parent7adfdf5248745b393e98ebfba0bdce6c2f0bfd84 (diff)
parent2399710356456ca7758b9ab3b7469cc67f21984e (diff)
downloadnextcloud-server-4f2923862ad7d499684571ded196f2d2fc85344a.tar.gz
nextcloud-server-4f2923862ad7d499684571ded196f2d2fc85344a.zip
Merge pull request #35108 from nextcloud/encryption-fix-versions-all
allow running encryption:fix-encrypted-version for all users
-rw-r--r--apps/encryption/lib/Command/FixEncryptedVersion.php51
-rw-r--r--apps/encryption/tests/Command/FixEncryptedVersionTest.php2
2 files changed, 39 insertions, 14 deletions
diff --git a/apps/encryption/lib/Command/FixEncryptedVersion.php b/apps/encryption/lib/Command/FixEncryptedVersion.php
index cace88476f8..925dc3dd805 100644
--- a/apps/encryption/lib/Command/FixEncryptedVersion.php
+++ b/apps/encryption/lib/Command/FixEncryptedVersion.php
@@ -29,10 +29,12 @@ use OCP\Files\IRootFolder;
use OCP\HintException;
use OCP\IConfig;
use OCP\ILogger;
+use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class FixEncryptedVersion extends Command {
@@ -84,13 +86,18 @@ class FixEncryptedVersion extends Command {
->setDescription('Fix the encrypted version if the encrypted file(s) are not downloadable.')
->addArgument(
'user',
- InputArgument::REQUIRED,
+ InputArgument::OPTIONAL,
'The id of the user whose files need fixing'
)->addOption(
'path',
'p',
- InputArgument::OPTIONAL,
+ InputOption::VALUE_REQUIRED,
'Limit files to fix with path, e.g., --path="/Music/Artist". If path indicates a directory, all the files inside directory will be fixed.'
+ )->addOption(
+ 'all',
+ null,
+ InputOption::VALUE_NONE,
+ 'Run the fix for all users on the system, mutually exclusive with specifying a user id.'
);
}
@@ -108,22 +115,40 @@ class FixEncryptedVersion extends Command {
return 1;
}
- $user = (string)$input->getArgument('user');
- $pathToWalk = "/$user/files";
-
+ $user = $input->getArgument('user');
+ $all = $input->getOption('all');
$pathOption = \trim(($input->getOption('path') ?? ''), '/');
- if ($pathOption !== "") {
- $pathToWalk = "$pathToWalk/$pathOption";
- }
- if ($user === '') {
- $output->writeln("<error>No user id provided.</error>\n");
+ if ($user) {
+ if ($all) {
+ $output->writeln("Specifying a user id and --all are mutually exclusive");
+ return 1;
+ }
+
+ if ($this->userManager->get($user) === null) {
+ $output->writeln("<error>User id $user does not exist. Please provide a valid user id</error>");
+ return 1;
+ }
+
+ return $this->runForUser($user, $pathOption, $output);
+ } elseif ($all) {
+ $result = 0;
+ $this->userManager->callForSeenUsers(function(IUser $user) use ($pathOption, $output, &$result) {
+ $output->writeln("Processing files for " . $user->getUID());
+ $result = $this->runForUser($user->getUID(), $pathOption, $output);
+ return $result === 0;
+ });
+ return $result;
+ } else {
+ $output->writeln("Either a user id or --all needs to be provided");
return 1;
}
+ }
- if ($this->userManager->get($user) === null) {
- $output->writeln("<error>User id $user does not exist. Please provide a valid user id</error>");
- return 1;
+ private function runForUser(string $user, string $pathOption, OutputInterface $output): int {
+ $pathToWalk = "/$user/files";
+ if ($pathOption !== "") {
+ $pathToWalk = "$pathToWalk/$pathOption";
}
return $this->walkPathOfUser($user, $pathToWalk, $output);
}
diff --git a/apps/encryption/tests/Command/FixEncryptedVersionTest.php b/apps/encryption/tests/Command/FixEncryptedVersionTest.php
index ee9ad1ac89f..5c938b4350d 100644
--- a/apps/encryption/tests/Command/FixEncryptedVersionTest.php
+++ b/apps/encryption/tests/Command/FixEncryptedVersionTest.php
@@ -344,7 +344,7 @@ The file \"/$this->userId/files/sub/hello.txt\" is: OK", $output);
$output = $this->commandTester->getDisplay();
- $this->assertStringContainsString('No user id provided', $output);
+ $this->assertStringContainsString('Either a user id or --all needs to be provided', $output);
}
public function testExecuteWithBadUser() {