diff --git a/core/Command/SystemTag/Edit.php b/core/Command/SystemTag/Edit.php index eb6412b763991..a4597d8463760 100644 --- a/core/Command/SystemTag/Edit.php +++ b/core/Command/SystemTag/Edit.php @@ -40,6 +40,12 @@ protected function configure() { null, InputOption::VALUE_OPTIONAL, 'sets the access control level (public, restricted, invisible)', + ) + ->addOption( + 'color', + null, + InputOption::VALUE_OPTIONAL, + 'set the tag color', ); } @@ -80,9 +86,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } + $color = $tag->getColor(); + if ($input->hasOption('color')) { + $color = $input->getOption('color'); + if (substr($color, 0, 1) === '#') { + $color = substr($color, 1); + } + + if ($input->getOption('color') === '') { + $color = ''; + } elseif (strlen($color) !== 6 || !ctype_xdigit($color)) { + $output->writeln('Color must be a 6-digit hexadecimal value'); + return 2; + } + } + try { - $this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable); - $output->writeln('Tag updated ("' . $name . '", ' . $userVisible . ', ' . $userAssignable . ')'); + $this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable, $color); + $output->writeln('Tag updated ("' . $name . '", ' . json_encode($userVisible) . ', ' . json_encode($userAssignable) . ', "' . ($color ? "#$color" : '') . '")'); return 0; } catch (TagNotFoundException $e) { $output->writeln('Tag not found'); diff --git a/tests/Core/Command/SystemTag/EditTest.php b/tests/Core/Command/SystemTag/EditTest.php index f269559190565..0d2f6ba4fbc9c 100644 --- a/tests/Core/Command/SystemTag/EditTest.php +++ b/tests/Core/Command/SystemTag/EditTest.php @@ -81,13 +81,14 @@ public function testExecute(): void { $tagId, $newTagName, $newTagUserVisible, - $newTagUserAssignable + $newTagUserAssignable, + '' ); $this->output->expects($this->once()) ->method('writeln') ->with( - 'Tag updated ("' . $newTagName . '", ' . $newTagUserVisible . ', ' . $newTagUserAssignable . ')' + 'Tag updated ("' . $newTagName . '", ' . json_encode($newTagUserVisible) . ', ' . json_encode($newTagUserAssignable) . ', "")' ); $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); @@ -145,7 +146,8 @@ public function testAlreadyExists(): void { $tagId, $newTagName, $newTagUserVisible, - $newTagUserAssignable + $newTagUserAssignable, + '' ); $this->output->expects($this->once())