diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2021-12-06 17:44:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-06 17:44:01 +0300 |
commit | db82c39b45cf09ec3a1679fc474fadc456da7a45 (patch) | |
tree | c6a44b03d28bc3a6e304061fbb49b3e4c3549ff0 | |
parent | c4cb6f6e6fcf34ee7d259186ec656bb687776434 (diff) | |
parent | dbbe3b1de16d5583f1140dfe0b066249c8b830b8 (diff) |
Merge pull request #259 from hammer065/feature/multiple-options
Feature: Multiple Options
-rw-r--r-- | lib/Command/DeleteOld.php | 16 | ||||
-rw-r--r-- | lib/Command/Generate.php | 36 |
2 files changed, 29 insertions, 23 deletions
diff --git a/lib/Command/DeleteOld.php b/lib/Command/DeleteOld.php index a9b4d19..464f93e 100644 --- a/lib/Command/DeleteOld.php +++ b/lib/Command/DeleteOld.php @@ -56,22 +56,24 @@ class DeleteOld extends Command { ->setDescription('Delete old preview folder (pre NC11)') ->addArgument( 'user_id', - InputArgument::OPTIONAL, - 'Delete old preview folder for the given user' + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'Delete old preview folder for the given user(s)' ); } protected function execute(InputInterface $input, OutputInterface $output): int { - $userId = $input->getArgument('user_id'); + $userIds = $input->getArgument('user_id'); - if ($userId === null) { + if (count($userIds) === 0) { $this->userManager->callForSeenUsers(function (IUser $user) { $this->deletePreviews($user); }); } else { - $user = $this->userManager->get($userId); - if ($user !== null) { - $this->deletePreviews($user); + foreach ($userIds as $userId) { + $user = $this->userManager->get($userId); + if ($user !== null) { + $this->deletePreviews($user); + } } } diff --git a/lib/Command/Generate.php b/lib/Command/Generate.php index f60fa06..c461fbc 100644 --- a/lib/Command/Generate.php +++ b/lib/Command/Generate.php @@ -91,13 +91,13 @@ class Generate extends Command { ->setDescription('Generate previews') ->addArgument( 'user_id', - InputArgument::OPTIONAL, - 'Generate previews for the given user' + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'Generate previews for the given user(s)' )->addOption( 'path', 'p', - InputOption::VALUE_OPTIONAL, - 'limit scan to this path, eg. --path="/alice/files/Photos", the user_id is determined by the path and the user_id parameter is ignored' + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + 'limit scan to this path, eg. --path="/alice/files/Photos", the user_id is determined by the path and all user_id arguments are ignored, multiple usages allowed' ); } @@ -114,24 +114,28 @@ class Generate extends Command { $this->sizes = SizeHelper::calculateSizes($this->config); - $inputPath = $input->getOption('path'); - if ($inputPath) { - $inputPath = '/' . trim($inputPath, '/'); - [, $userId,] = explode('/', $inputPath, 3); - $user = $this->userManager->get($userId); - if ($user !== null) { - $this->generatePathPreviews($user, $inputPath); + $inputPaths = $input->getOption('path'); + if ($inputPaths) { + foreach ($inputPaths as $inputPath) { + $inputPath = '/' . trim($inputPath, '/'); + [, $userId,] = explode('/', $inputPath, 3); + $user = $this->userManager->get($userId); + if ($user !== null) { + $this->generatePathPreviews($user, $inputPath); + } } } else { - $userId = $input->getArgument('user_id'); - if ($userId === null) { + $userIds = $input->getArgument('user_id'); + if (count($userIds) === 0) { $this->userManager->callForSeenUsers(function (IUser $user) { $this->generateUserPreviews($user); }); } else { - $user = $this->userManager->get($userId); - if ($user !== null) { - $this->generateUserPreviews($user); + foreach ($userIds as $userId) { + $user = $this->userManager->get($userId); + if ($user !== null) { + $this->generateUserPreviews($user); + } } } } |