Default behaviour when no users are specified on trashbin:cleanup
* Add option --all-users to explicitly clean all trashbins * Reject no users on commandline and no --all-users * Warn when --all-users and userids are specified Signed-off-by: Liam Dennehy <liam@wiemax.net>
This commit is contained in:
parent
388ea2234f
commit
6bc3d3781d
|
@ -29,6 +29,7 @@ use OCP\IUserBackend;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
@ -62,13 +63,22 @@ class CleanUp extends Command {
|
||||||
->addArgument(
|
->addArgument(
|
||||||
'user_id',
|
'user_id',
|
||||||
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
|
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
|
||||||
'remove deleted files of the given user(s), if no user is given all deleted files will be removed'
|
'remove deleted files of the given user(s)'
|
||||||
|
)
|
||||||
|
->addOption(
|
||||||
|
'all-users',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'run action on all users'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||||
$users = $input->getArgument('user_id');
|
$users = $input->getArgument('user_id');
|
||||||
if (!empty($users)) {
|
if (!empty($users)) {
|
||||||
|
if ($input->getOption('all-users')) {
|
||||||
|
$output->writeln('Option --all-users supplied along with users, restricting to supplied users');
|
||||||
|
}
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
if ($this->userManager->userExists($user)) {
|
if ($this->userManager->userExists($user)) {
|
||||||
$output->writeln("Remove deleted files of <info>$user</info>");
|
$output->writeln("Remove deleted files of <info>$user</info>");
|
||||||
|
@ -77,8 +87,8 @@ class CleanUp extends Command {
|
||||||
$output->writeln("<error>Unknown user $user</error>");
|
$output->writeln("<error>Unknown user $user</error>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($input->getOption('all-users')) {
|
||||||
$output->writeln('Remove all deleted files');
|
$output->writeln('Remove deleted files for all users');
|
||||||
foreach ($this->userManager->getBackends() as $backend) {
|
foreach ($this->userManager->getBackends() as $backend) {
|
||||||
$name = get_class($backend);
|
$name = get_class($backend);
|
||||||
if ($backend instanceof IUserBackend) {
|
if ($backend instanceof IUserBackend) {
|
||||||
|
|
Loading…
Reference in New Issue