X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FEntry.php;h=beda581af2ee214abb96c11a6fd48eb6af30908b;hb=48b0163d247554d7e2f1ec63b717c8216ea9ec59;hp=2b1f2e050799c24495611d2ba75212e37944f4d5;hpb=773ac5b0f7a56ff2527601498b0822d6ef8bfa40;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 2b1f2e05..beda581a 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -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; /** @@ -25,7 +26,13 @@ use Wallabag\UserBundle\Entity\User; * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, * indexes={ * @ORM\Index(name="created_at", columns={"created_at"}), - * @ORM\Index(name="uid", columns={"uid"}) + * @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_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_created", columns={"user_id", "created_at"}), + * @ORM\Index(name="user_starred", columns={"user_id", "is_starred", "starred_at"}) * } * ) * @ORM\HasLifecycleCallbacks() @@ -66,6 +73,8 @@ class Entry private $title; /** + * Define the url fetched by wallabag (the final url after potential redirections). + * * @var string * * @Assert\NotBlank() @@ -75,6 +84,42 @@ class Entry */ private $url; + /** + * @var string + * + * @ORM\Column(name="hashed_url", type="string", length=40, nullable=true) + */ + 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 * @@ -86,6 +131,15 @@ class Entry */ private $isArchived = false; + /** + * @var \DateTime + * + * @ORM\Column(name="archived_at", type="datetime", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $archivedAt = null; + /** * @var bool * @@ -171,7 +225,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"}) */ @@ -245,15 +299,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 */ @@ -307,6 +352,7 @@ class Entry public function setUrl($url) { $this->url = $url; + $this->hashedUrl = UrlHasher::hashUrl($url); return $this; } @@ -335,6 +381,44 @@ class Entry return $this; } + /** + * update isArchived and archive_at fields. + * + * @param bool $isArchived + * + * @return Entry + */ + public function updateArchived($isArchived = false) + { + $this->setArchived($isArchived); + $this->setArchivedAt(null); + if ($this->isArchived()) { + $this->setArchivedAt(new \DateTime()); + } + + return $this; + } + + /** + * @return \DateTime|null + */ + public function getArchivedAt() + { + return $this->archivedAt; + } + + /** + * @param \DateTime|null $archivedAt + * + * @return Entry + */ + public function setArchivedAt($archivedAt = null) + { + $this->archivedAt = $archivedAt; + + return $this; + } + /** * Get isArchived. * @@ -357,7 +441,7 @@ class Entry public function toggleArchive() { - $this->isArchived = $this->isArchived() ^ 1; + $this->updateArchived($this->isArchived() ^ 1); return $this; } @@ -466,8 +550,6 @@ class Entry * Set created_at. * Only used when importing data from an other service. * - * @param \DateTime $createdAt - * * @return Entry */ public function setCreatedAt(\DateTime $createdAt) @@ -539,9 +621,6 @@ class Entry return $this->annotations; } - /** - * @param Annotation $annotation - */ public function setAnnotation(Annotation $annotation) { $this->annotations[] = $annotation; @@ -618,9 +697,6 @@ class Entry return $data; } - /** - * @param Tag $tag - */ public function addTag(Tag $tag) { if ($this->tags->contains($tag)) { @@ -641,8 +717,6 @@ class Entry /** * Remove the given tag from the entry (if the tag is associated). - * - * @param Tag $tag */ public function removeTag(Tag $tag) { @@ -714,7 +788,7 @@ class Entry } /** - * @return string + * @return string|null */ public function getUid() { @@ -790,8 +864,6 @@ class Entry } /** - * @param \Datetime $publishedAt - * * @return Entry */ public function setPublishedAt(\Datetime $publishedAt) @@ -864,4 +936,49 @@ 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 + */ + public function getHashedUrl() + { + return $this->hashedUrl; + } + + /** + * @param mixed $hashedUrl + * + * @return Entry + */ + public function setHashedUrl($hashedUrl) + { + $this->hashedUrl = $hashedUrl; + + return $this; + } }