mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-13 05:39:33 +00:00
Tidy up tag deletion
This commit is contained in:
parent
26ee564481
commit
2e15f87f6e
1 changed files with 6 additions and 5 deletions
|
|
@ -140,14 +140,15 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
|
|||
case "add_tag":
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
$tags = $part->getTags();
|
||||
$part->setTags($tags . ',' . $target_id); // simple append
|
||||
// simple append
|
||||
$part->setTags($tags.','.$target_id);
|
||||
break;
|
||||
case "remove_tag":
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
$tags = $part->getTags();
|
||||
$tags = str_replace($target_id, '', $tags);
|
||||
// sanitize $tags (remove leading, trailing and double commas)
|
||||
$part->setTags($tags);
|
||||
// remove tag at start or end
|
||||
$tags = preg_replace("/(^".$target_id.",|,".$target_id."$)/", '', $part->getTags());
|
||||
// remove tag in the middle, retaining one comma
|
||||
$tags = str_replace(','.$target_id.',', ',' $tags);
|
||||
break;
|
||||
case 'favorite':
|
||||
$this->denyAccessUnlessGranted('change_favorite', $part);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue