]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
Add user_archived index
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index c3fb87d218630875e77047002fad2bad55b091d1..49f19cfa0db1f6da937ea4167f2b4761c4019169 100644 (file)
@@ -13,6 +13,7 @@ use JMS\Serializer\Annotation\XmlRoot;
 use Symfony\Component\Validator\Constraints as Assert;
 use Wallabag\AnnotationBundle\Entity\Annotation;
 use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
+use Wallabag\CoreBundle\Helper\UrlHasher;
 use Wallabag\UserBundle\Entity\User;
 
 /**
@@ -26,7 +27,11 @@ use Wallabag\UserBundle\Entity\User;
  *     indexes={
  *         @ORM\Index(name="created_at", columns={"created_at"}),
  *         @ORM\Index(name="uid", columns={"uid"}),
- *         @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}})
+ *         @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}),
+ *         @ORM\Index(name="hashed_given_url_user_id", columns={"user_id", "hashed_given_url"}, options={"lengths"={null, 40}}),
+ *         @ORM\Index(name="user_language", columns={"language", "user_id"}),
+ *         @ORM\Index(name="user_archived", columns={"user_id", "is_archived", "archived_at"}),
+ *         @ORM\Index(name="user_starred", columns={"user_id", "is_starred", "starred_at"})
  *     }
  * )
  * @ORM\HasLifecycleCallbacks()
@@ -67,6 +72,8 @@ class Entry
     private $title;
 
     /**
+     * Define the url fetched by wallabag (the final url after potential redirections).
+     *
      * @var string
      *
      * @Assert\NotBlank()
@@ -83,6 +90,35 @@ class Entry
      */
     private $hashedUrl;
 
+    /**
+     * From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided).
+     *
+     * @var string
+     *
+     * @ORM\Column(name="origin_url", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    private $originUrl;
+
+    /**
+     * Define the url entered by the user (without redirections).
+     *
+     * @var string
+     *
+     * @ORM\Column(name="given_url", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    private $givenUrl;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="hashed_given_url", type="string", length=40, nullable=true)
+     */
+    private $hashedGivenUrl;
+
     /**
      * @var bool
      *
@@ -188,7 +224,7 @@ class Entry
     /**
      * @var string
      *
-     * @ORM\Column(name="language", type="text", nullable=true)
+     * @ORM\Column(name="language", type="string", length=20, nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
@@ -262,15 +298,6 @@ class Entry
      */
     private $tags;
 
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="origin_url", type="text", nullable=true)
-     *
-     * @Groups({"entries_for_user", "export_all"})
-     */
-    private $originUrl;
-
     /*
      * @param User     $user
      */
@@ -324,7 +351,7 @@ class Entry
     public function setUrl($url)
     {
         $this->url = $url;
-        $this->hashedUrl = hash('sha1', $url);
+        $this->hashedUrl = UrlHasher::hashUrl($url);
 
         return $this;
     }
@@ -770,7 +797,7 @@ class Entry
     }
 
     /**
-     * @return string
+     * @return string|null
      */
     public function getUid()
     {
@@ -921,6 +948,31 @@ class Entry
         return $this->originUrl;
     }
 
+    /**
+     * Set given url.
+     *
+     * @param string $givenUrl
+     *
+     * @return Entry
+     */
+    public function setGivenUrl($givenUrl)
+    {
+        $this->givenUrl = $givenUrl;
+        $this->hashedGivenUrl = UrlHasher::hashUrl($givenUrl);
+
+        return $this;
+    }
+
+    /**
+     * Get given url.
+     *
+     * @return string
+     */
+    public function getGivenUrl()
+    {
+        return $this->givenUrl;
+    }
+
     /**
      * @return string
      */