]> 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 a2bb507eacf4f500233a45f092fd6e1a2b759e19..b413c489c7c9291922a4b9a8fc6fea1860711011 100644 (file)
@@ -6,7 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 use Hateoas\Configuration\Annotation as Hateoas;
-use Symfony\Component\Serializer\Annotation\Groups;
+use JMS\Serializer\Annotation\Groups;
 use JMS\Serializer\Annotation\XmlRoot;
 use Wallabag\UserBundle\Entity\User;
 
@@ -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);
     }