From 26d8649f9944faf34f57cdfe9de2261913f48b51 Mon Sep 17 00:00:00 2001 From: luizlaydner Date: Thu, 2 Aug 2007 14:16:45 +0000 Subject: [PATCH] added a record_exists check before creating tags and tag_instances --- tag/lib.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tag/lib.php b/tag/lib.php index 7bb1463c7a..b372b0b8ad 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -32,13 +32,15 @@ function tag_create($tag_names_csv, $tag_type="default") { // rawname keeps the original casing of the string $tag_object->rawname = tag_normalize($tag, false); - // name lowecases the string + // name lowercases the string $tag_object->name = tag_normalize($tag); $norm_tag_names_csv .= $tag_object->name . ','; + + $tag_object->timemodified = time(); - $tag_object->timemodified = time(); - - if ( $can_create_tags && !empty($tag_object->name) && !is_numeric($tag_object->name) ) { + $exists = record_exists('tag', 'name', $tag_object->name); + + if ( $can_create_tags && !$exists && !empty($tag_object->name) && !is_numeric($tag_object->name) ) { insert_record('tag', $tag_object); } } @@ -345,8 +347,14 @@ function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="def //create tag instances foreach ($tags_created_ids as $tag_id) { + $tag_instance->tagid = $tag_id; - insert_record('tag_instance',$tag_instance); + + $exists = record_exists('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id); + + if (!$exists) { + insert_record('tag_instance',$tag_instance); + } } -- 2.39.5