From fea4fa1c4f1461c27579a0acd1c548349e2939c4 Mon Sep 17 00:00:00 2001 From: schaarsc Date: Sun, 6 Oct 2024 14:14:29 +0200 Subject: [PATCH] feat(SystemTags) add option to only list tags not used by files Signed-off-by: schaarsc --- core/Command/SystemTag/ListCommand.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/Command/SystemTag/ListCommand.php b/core/Command/SystemTag/ListCommand.php index 836869f157dc7..e550bf1883919 100644 --- a/core/Command/SystemTag/ListCommand.php +++ b/core/Command/SystemTag/ListCommand.php @@ -8,6 +8,7 @@ use OC\Core\Command\Base; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagObjectMapper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -15,6 +16,7 @@ class ListCommand extends Base { public function __construct( protected ISystemTagManager $systemTagManager, + protected ISystemTagObjectMapper $systemTagObjectMapper, ) { parent::__construct(); } @@ -34,6 +36,12 @@ protected function configure() { null, InputOption::VALUE_OPTIONAL, 'optional search pattern for the tag name (infix)' + ) + ->addOption( + 'notUsedByFiles', + null, + InputOption::VALUE_OPTIONAL, + 'not used by files (1,0)' ); parent::configure(); } @@ -44,6 +52,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int $input->getOption('nameSearchPattern') ); + if ($input->getOption('notUsedByFiles') == 1) { + $result = []; + foreach ($tags as $tag) { + $objId = $this->systemTagObjectMapper->getObjectIdsForTags((string)$tag->getId(), 'files', 1); + if ($objId == null) { + $result[] = $tag; + } + } + $tags = $result; + } + $this->writeArrayInOutputFormat($input, $output, $this->formatTags($tags)); return 0; }