setName('tag:files:delete') ->setDescription('Delete a system-tag from a file or folder') ->addArgument('target', InputArgument::REQUIRED, 'file id or path') ->addArgument('tags', InputArgument::REQUIRED, 'Name of the tag(s) to delete, comma separated') ->addArgument('access', InputArgument::REQUIRED, 'access level of the tag (public, restricted or invisible)'); } public function execute(InputInterface $input, OutputInterface $output): int { $targetInput = $input->getArgument('target'); $tagsInput = $input->getArgument('tags'); if ($tagsInput === '') { $output->writeln('`tags` can\'t be empty'); return 3; } $tagNameArray = explode(',', $tagsInput); $access = $input->getArgument('access'); switch ($access) { case 'public': $userVisible = true; $userAssignable = true; break; case 'restricted': $userVisible = true; $userAssignable = false; break; case 'invisible': $userVisible = false; $userAssignable = false; break; default: $output->writeln('`access` property is invalid'); return 1; } $targetNode = $this->fileUtils->getNode($targetInput); if (! $targetNode) { $output->writeln("file $targetInput not found"); return 1; } foreach ($tagNameArray as $tagName) { try { $tag = $this->systemTagManager->getTag($tagName, $userVisible, $userAssignable); $this->systemTagObjectMapper->unassignTags((string)$targetNode->getId(), 'files', $tag->getId()); $output->writeln("$access tag named $tagName removed."); } catch (TagNotFoundException $e) { $output->writeln("$access tag named $tagName does not exist!"); } } return 0; } }