]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
Remove user reference in tag
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index 5aa582f8d434a1c4638ca3127a41d9efe5501cfb..b413c489c7c9291922a4b9a8fc6fea1860711011 100644 (file)
@@ -458,6 +458,18 @@ class Entry
      */
     public function addTag(Tag $tag)
     {
+        if ($this->tags->contains($tag)) {
+            return;
+        }
+
+        // check if tag already exist but has not yet be persisted
+        // it seems that the previous condition with `contains()` doesn't check that case
+        foreach ($this->tags as $existingTag) {
+            if ($existingTag->getLabel() === $tag->getLabel()) {
+                return;
+            }
+        }
+
         $this->tags[] = $tag;
         $tag->addEntry($this);
     }