Changed to prevent writing duplicate image tag IDs
This commit is contained in:
parent
4410baeb9c
commit
b7945b098e
1 changed files with 13 additions and 4 deletions
|
@ -603,6 +603,9 @@ class Image
|
||||||
if (Tag::implode($tags) != $this->get_tag_list()) {
|
if (Tag::implode($tags) != $this->get_tag_list()) {
|
||||||
// delete old
|
// delete old
|
||||||
$this->delete_tags_from_image();
|
$this->delete_tags_from_image();
|
||||||
|
|
||||||
|
$written_tags = [];
|
||||||
|
|
||||||
// insert each new tags
|
// insert each new tags
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$id = $database->get_one(
|
$id = $database->get_one(
|
||||||
|
@ -625,11 +628,17 @@ class Image
|
||||||
["id"=>$this->id, "tag"=>$tag]
|
["id"=>$this->id, "tag"=>$tag]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// user of an existing tag
|
// check if tag has already been written
|
||||||
|
if(in_array($id, $written_tags)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$database->execute("
|
$database->execute("
|
||||||
INSERT INTO image_tags(image_id, tag_id)
|
INSERT INTO image_tags(image_id, tag_id)
|
||||||
VALUES(:iid, :tid)
|
VALUES(:iid, :tid)
|
||||||
", ["iid"=>$this->id, "tid"=>$id]);
|
", ["iid"=>$this->id, "tid"=>$id]);
|
||||||
|
|
||||||
|
array_push($written_tags, $id);
|
||||||
}
|
}
|
||||||
$database->execute(
|
$database->execute(
|
||||||
$database->scoreql_to_sql("
|
$database->scoreql_to_sql("
|
||||||
|
|
Reference in a new issue