Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added a record_exists check before creating tags and tag_instances

  • Loading branch information...
commit 26d8649f9944faf34f57cdfe9de2261913f48b51 1 parent 8942ac9
luizlaydner authored

Showing 1 changed file with 13 additions and 5 deletions. Show diff stats Hide diff stats

  1. +13 5 tag/lib.php
18 tag/lib.php
@@ -32,13 +32,15 @@ function tag_create($tag_names_csv, $tag_type="default") {
32 32 // rawname keeps the original casing of the string
33 33 $tag_object->rawname = tag_normalize($tag, false);
34 34
35   - // name lowecases the string
  35 + // name lowercases the string
36 36 $tag_object->name = tag_normalize($tag);
37 37 $norm_tag_names_csv .= $tag_object->name . ',';
  38 +
  39 + $tag_object->timemodified = time();
38 40
39   - $tag_object->timemodified = time();
40   -
41   - if ( $can_create_tags && !empty($tag_object->name) && !is_numeric($tag_object->name) ) {
  41 + $exists = record_exists('tag', 'name', $tag_object->name);
  42 +
  43 + if ( $can_create_tags && !$exists && !empty($tag_object->name) && !is_numeric($tag_object->name) ) {
42 44 insert_record('tag', $tag_object);
43 45 }
44 46 }
@@ -345,8 +347,14 @@ function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="def
345 347
346 348 //create tag instances
347 349 foreach ($tags_created_ids as $tag_id) {
  350 +
348 351 $tag_instance->tagid = $tag_id;
349   - insert_record('tag_instance',$tag_instance);
  352 +
  353 + $exists = record_exists('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id);
  354 +
  355 + if (!$exists) {
  356 + insert_record('tag_instance',$tag_instance);
  357 + }
350 358 }
351 359
352 360

0 comments on commit 26d8649

Please sign in to comment.
Something went wrong with that request. Please try again.