Skip to content

Commit b1e0ccc

Browse files
committed
allow running encryption:fix-encrypted-version for all users
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent cc83222 commit b1e0ccc

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

apps/encryption/lib/Command/FixEncryptedVersion.php

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
use OCP\HintException;
3030
use OCP\IConfig;
3131
use OCP\ILogger;
32+
use OCP\IUser;
3233
use OCP\IUserManager;
3334
use Symfony\Component\Console\Command\Command;
3435
use Symfony\Component\Console\Input\InputArgument;
3536
use Symfony\Component\Console\Input\InputInterface;
37+
use Symfony\Component\Console\Input\InputOption;
3638
use Symfony\Component\Console\Output\OutputInterface;
3739

3840
class FixEncryptedVersion extends Command {
@@ -84,13 +86,18 @@ protected function configure(): void {
8486
->setDescription('Fix the encrypted version if the encrypted file(s) are not downloadable.')
8587
->addArgument(
8688
'user',
87-
InputArgument::REQUIRED,
89+
InputArgument::OPTIONAL,
8890
'The id of the user whose files need fixing'
8991
)->addOption(
9092
'path',
9193
'p',
92-
InputArgument::OPTIONAL,
94+
InputOption::VALUE_REQUIRED,
9395
'Limit files to fix with path, e.g., --path="/Music/Artist". If path indicates a directory, all the files inside directory will be fixed.'
96+
)->addOption(
97+
'all',
98+
null,
99+
InputOption::VALUE_NONE,
100+
'Run the fix for all users on the system, mutually exclusive with specifying a user id.'
94101
);
95102
}
96103

@@ -108,22 +115,42 @@ protected function execute(InputInterface $input, OutputInterface $output): int
108115
return 1;
109116
}
110117

111-
$user = (string)$input->getArgument('user');
112-
$pathToWalk = "/$user/files";
113-
118+
$user = $input->getArgument('user');
119+
$all = $input->getOption('all');
114120
$pathOption = \trim(($input->getOption('path') ?? ''), '/');
115-
if ($pathOption !== "") {
116-
$pathToWalk = "$pathToWalk/$pathOption";
117-
}
118121

119-
if ($user === '') {
120-
$output->writeln("<error>No user id provided.</error>\n");
122+
if ($user) {
123+
if ($all) {
124+
$output->writeln("Specifying a user id and --all are mutually exclusive");
125+
return 1;
126+
}
127+
128+
if ($this->userManager->get($user) === null) {
129+
$output->writeln("<error>User id $user does not exist. Please provide a valid user id</error>");
130+
return 1;
131+
}
132+
133+
return $this->runForUser($user, $pathOption, $output);
134+
} else if ($all) {
135+
$result = 0;
136+
$this->userManager->callForSeenUsers(function(IUser $user) use ($pathOption, $output, &$result) {
137+
$output->writeln("Processing files for " . $user->getUID());
138+
$result = $this->runForUser($user->getUID(), $pathOption, $output);
139+
if ($result !== 0) {
140+
return false;
141+
}
142+
});
143+
return $result;
144+
} else {
145+
$output->writeln("Either a user id or --all needs to be provider");
121146
return 1;
122147
}
148+
}
123149

124-
if ($this->userManager->get($user) === null) {
125-
$output->writeln("<error>User id $user does not exist. Please provide a valid user id</error>");
126-
return 1;
150+
private function runForUser(string $user, string $pathOption, OutputInterface $output): int {
151+
$pathToWalk = "/$user/files";
152+
if ($pathOption !== "") {
153+
$pathToWalk = "$pathToWalk/$pathOption";
127154
}
128155
return $this->walkPathOfUser($user, $pathToWalk, $output);
129156
}

0 commit comments

Comments
 (0)