Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] allow running encryption:fix-encrypted-version for all users #35865

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 38 additions & 13 deletions apps/encryption/lib/Command/FixEncryptedVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
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 {
Expand Down Expand Up @@ -84,13 +86,18 @@ protected function configure(): void {
->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.'
);
}

Expand All @@ -108,22 +115,40 @@ protected function execute(InputInterface $input, OutputInterface $output): int
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);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/encryption/tests/Command/FixEncryptedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function testExecuteWithNoUser() {

$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() {
Expand Down