Allows appending new tags to existing ones in auto_tagger
This commit is contained in:
parent
3154a833f7
commit
ccb78e272c
1 changed files with 22 additions and 5 deletions
|
@ -210,8 +210,26 @@ class AutoTagger extends Extension
|
||||||
private function add_auto_tag(string $tag, string $additional_tags)
|
private function add_auto_tag(string $tag, string $additional_tags)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
if ($database->exists("SELECT * FROM auto_tag WHERE LOWER(tag)=LOWER(:tag)", ["tag"=>$tag])) {
|
$existing_tags = $database->get_one("SELECT additional_tags FROM auto_tag WHERE LOWER(tag)=LOWER(:tag)", ["tag"=>$tag]);
|
||||||
throw new AutoTaggerException("Auto-Tag is already set for that tag");
|
if (!is_null($existing_tags)) {
|
||||||
|
// Auto Tags already exist, so we will append new tags to the existing one
|
||||||
|
$tag = Tag::sanitize($tag);
|
||||||
|
$additional_tags = Tag::explode($additional_tags);
|
||||||
|
$existing_tags = Tag::explode($existing_tags);
|
||||||
|
foreach ($additional_tags as $t) {
|
||||||
|
if (!in_array(strtolower($t), $existing_tags)) {
|
||||||
|
array_push($existing_tags, strtolower($t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$database->execute(
|
||||||
|
"UPDATE auto_tag set additional_tags=:existing_tags where tag=:tag",
|
||||||
|
["tag"=>$tag, "existing_tags"=>Tag::implode($existing_tags)]
|
||||||
|
);
|
||||||
|
log_info(
|
||||||
|
AutoTaggerInfo::KEY,
|
||||||
|
"Updated auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}"
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$tag = Tag::sanitize($tag);
|
$tag = Tag::sanitize($tag);
|
||||||
$additional_tags = Tag::explode($additional_tags);
|
$additional_tags = Tag::explode($additional_tags);
|
||||||
|
@ -225,11 +243,10 @@ class AutoTagger extends Extension
|
||||||
AutoTaggerInfo::KEY,
|
AutoTaggerInfo::KEY,
|
||||||
"Added auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}"
|
"Added auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
// Now we apply it to existing items
|
// Now we apply it to existing items
|
||||||
$this->apply_new_auto_tag($tag);
|
$this->apply_new_auto_tag($tag);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function update_auto_tag(string $tag, string $additional_tags): bool
|
private function update_auto_tag(string $tag, string $additional_tags): bool
|
||||||
{
|
{
|
||||||
|
|
Reference in a new issue