]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
Change share entry behavior
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index 1271f1f5f2657941c497f47f07b18a468db402ca..8c20cde22e938d9df424d9b2c823540071386a64 100644 (file)
@@ -37,6 +37,15 @@ class Entry
      */
     private $id;
 
+    /**
+     * @var int
+     *
+     * @ORM\Column(name="uuid", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    private $uuid;
+
     /**
      * @var string
      *
@@ -177,8 +186,16 @@ class Entry
     private $user;
 
     /**
-     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist", "remove"})
-     * @ORM\JoinTable
+     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
+     * @ORM\JoinTable(
+     *  name="entry_tag",
+     *  joinColumns={
+     *      @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
+     *  },
+     *  inverseJoinColumns={
+     *      @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
+     *  }
+     * )
      *
      * @Groups({"entries_for_user", "export_all"})
      */
@@ -526,13 +543,18 @@ class Entry
             }
         }
 
-        $this->tags[] = $tag;
+        $this->tags->add($tag);
         $tag->addEntry($this);
     }
 
     public function removeTag(Tag $tag)
     {
+        if (!$this->tags->contains($tag)) {
+            return;
+        }
+
         $this->tags->removeElement($tag);
+        $tag->removeEntry($this);
     }
 
     /**
@@ -582,4 +604,37 @@ class Entry
     {
         return $this->language;
     }
+
+    /**
+     * @return int
+     */
+    public function getUuid()
+    {
+        return $this->uuid;
+    }
+
+    /**
+     * @param int $uuid
+     *
+     * @return Entry
+     */
+    public function setUuid($uuid)
+    {
+        $this->uuid = $uuid;
+
+        return $this;
+    }
+
+    public function generateUuid()
+    {
+        if (empty($this->uuid) || is_null($this->uuid)) {
+            // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
+            $this->uuid = uniqid('', true);
+        }
+    }
+
+    public function cleanUuid()
+    {
+        $this->uuid = null;
+    }
 }