Skip to content

Commit

Permalink
feat(systemtags): allow setting color with occ
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Dec 4, 2024
1 parent 93c6632 commit 8b6216f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
25 changes: 23 additions & 2 deletions core/Command/SystemTag/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -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('<error>Color must be a 6-digit hexadecimal value</error>');
return 2;
}
}

try {
$this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable);
$output->writeln('<info>Tag updated ("' . $name . '", ' . $userVisible . ', ' . $userAssignable . ')</info>');
$this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable, $color);
$output->writeln('<info>Tag updated ("' . $name . '", ' . json_encode($userVisible) . ', ' . json_encode($userAssignable) . ', "' . ($color ? "#$color" : '') . '")</info>');
return 0;
} catch (TagNotFoundException $e) {
$output->writeln('<error>Tag not found</error>');
Expand Down
8 changes: 5 additions & 3 deletions tests/Core/Command/SystemTag/EditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ public function testExecute(): void {
$tagId,
$newTagName,
$newTagUserVisible,
$newTagUserAssignable
$newTagUserAssignable,
''
);

$this->output->expects($this->once())
->method('writeln')
->with(
'<info>Tag updated ("' . $newTagName . '", ' . $newTagUserVisible . ', ' . $newTagUserAssignable . ')</info>'
'<info>Tag updated ("' . $newTagName . '", ' . json_encode($newTagUserVisible) . ', ' . json_encode($newTagUserAssignable) . ', "")</info>'
);

$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
Expand Down Expand Up @@ -145,7 +146,8 @@ public function testAlreadyExists(): void {
$tagId,
$newTagName,
$newTagUserVisible,
$newTagUserAssignable
$newTagUserAssignable,
''
);

$this->output->expects($this->once())
Expand Down

0 comments on commit 8b6216f

Please sign in to comment.