diff options
author | lizyn <zhiylin@outlook.com> | 2020-02-24 10:04:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-24 10:04:13 +0800 |
commit | b19df31d78d881a43bcf6b3215e5fc3781e8e8aa (patch) | |
tree | d0d9861694a4b5e5fbfdbeb53c255ecd15fe9328 /src/Wallabag/CoreBundle/Entity/Entry.php | |
parent | 4d0c632c70ea50d459c3c55ddda2e0f394dd51cb (diff) | |
parent | 04d918cae0227c06a41d27fb6533dddbf30dfe71 (diff) | |
download | wallabag-b19df31d78d881a43bcf6b3215e5fc3781e8e8aa.tar.gz wallabag-b19df31d78d881a43bcf6b3215e5fc3781e8e8aa.tar.zst wallabag-b19df31d78d881a43bcf6b3215e5fc3781e8e8aa.zip |
Merge pull request #1 from wallabag/master
Keep up with the master again
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/Entry.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 180 |
1 files changed, 155 insertions, 25 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 2b1f2e05..19045798 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -13,6 +13,7 @@ use JMS\Serializer\Annotation\XmlRoot; | |||
13 | use Symfony\Component\Validator\Constraints as Assert; | 13 | use Symfony\Component\Validator\Constraints as Assert; |
14 | use Wallabag\AnnotationBundle\Entity\Annotation; | 14 | use Wallabag\AnnotationBundle\Entity\Annotation; |
15 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; | 15 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; |
16 | use Wallabag\CoreBundle\Helper\UrlHasher; | ||
16 | use Wallabag\UserBundle\Entity\User; | 17 | use Wallabag\UserBundle\Entity\User; |
17 | 18 | ||
18 | /** | 19 | /** |
@@ -25,7 +26,13 @@ use Wallabag\UserBundle\Entity\User; | |||
25 | * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, | 26 | * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, |
26 | * indexes={ | 27 | * indexes={ |
27 | * @ORM\Index(name="created_at", columns={"created_at"}), | 28 | * @ORM\Index(name="created_at", columns={"created_at"}), |
28 | * @ORM\Index(name="uid", columns={"uid"}) | 29 | * @ORM\Index(name="uid", columns={"uid"}), |
30 | * @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}), | ||
31 | * @ORM\Index(name="hashed_given_url_user_id", columns={"user_id", "hashed_given_url"}, options={"lengths"={null, 40}}), | ||
32 | * @ORM\Index(name="user_language", columns={"language", "user_id"}), | ||
33 | * @ORM\Index(name="user_archived", columns={"user_id", "is_archived", "archived_at"}), | ||
34 | * @ORM\Index(name="user_created", columns={"user_id", "created_at"}), | ||
35 | * @ORM\Index(name="user_starred", columns={"user_id", "is_starred", "starred_at"}) | ||
29 | * } | 36 | * } |
30 | * ) | 37 | * ) |
31 | * @ORM\HasLifecycleCallbacks() | 38 | * @ORM\HasLifecycleCallbacks() |
@@ -66,6 +73,8 @@ class Entry | |||
66 | private $title; | 73 | private $title; |
67 | 74 | ||
68 | /** | 75 | /** |
76 | * Define the url fetched by wallabag (the final url after potential redirections). | ||
77 | * | ||
69 | * @var string | 78 | * @var string |
70 | * | 79 | * |
71 | * @Assert\NotBlank() | 80 | * @Assert\NotBlank() |
@@ -76,6 +85,42 @@ class Entry | |||
76 | private $url; | 85 | private $url; |
77 | 86 | ||
78 | /** | 87 | /** |
88 | * @var string | ||
89 | * | ||
90 | * @ORM\Column(name="hashed_url", type="string", length=40, nullable=true) | ||
91 | */ | ||
92 | private $hashedUrl; | ||
93 | |||
94 | /** | ||
95 | * From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided). | ||
96 | * | ||
97 | * @var string | ||
98 | * | ||
99 | * @ORM\Column(name="origin_url", type="text", nullable=true) | ||
100 | * | ||
101 | * @Groups({"entries_for_user", "export_all"}) | ||
102 | */ | ||
103 | private $originUrl; | ||
104 | |||
105 | /** | ||
106 | * Define the url entered by the user (without redirections). | ||
107 | * | ||
108 | * @var string | ||
109 | * | ||
110 | * @ORM\Column(name="given_url", type="text", nullable=true) | ||
111 | * | ||
112 | * @Groups({"entries_for_user", "export_all"}) | ||
113 | */ | ||
114 | private $givenUrl; | ||
115 | |||
116 | /** | ||
117 | * @var string | ||
118 | * | ||
119 | * @ORM\Column(name="hashed_given_url", type="string", length=40, nullable=true) | ||
120 | */ | ||
121 | private $hashedGivenUrl; | ||
122 | |||
123 | /** | ||
79 | * @var bool | 124 | * @var bool |
80 | * | 125 | * |
81 | * @Exclude | 126 | * @Exclude |
@@ -87,6 +132,15 @@ class Entry | |||
87 | private $isArchived = false; | 132 | private $isArchived = false; |
88 | 133 | ||
89 | /** | 134 | /** |
135 | * @var \DateTime | ||
136 | * | ||
137 | * @ORM\Column(name="archived_at", type="datetime", nullable=true) | ||
138 | * | ||
139 | * @Groups({"entries_for_user", "export_all"}) | ||
140 | */ | ||
141 | private $archivedAt = null; | ||
142 | |||
143 | /** | ||
90 | * @var bool | 144 | * @var bool |
91 | * | 145 | * |
92 | * @Exclude | 146 | * @Exclude |
@@ -171,7 +225,7 @@ class Entry | |||
171 | /** | 225 | /** |
172 | * @var string | 226 | * @var string |
173 | * | 227 | * |
174 | * @ORM\Column(name="language", type="text", nullable=true) | 228 | * @ORM\Column(name="language", type="string", length=20, nullable=true) |
175 | * | 229 | * |
176 | * @Groups({"entries_for_user", "export_all"}) | 230 | * @Groups({"entries_for_user", "export_all"}) |
177 | */ | 231 | */ |
@@ -245,15 +299,6 @@ class Entry | |||
245 | */ | 299 | */ |
246 | private $tags; | 300 | private $tags; |
247 | 301 | ||
248 | /** | ||
249 | * @var string | ||
250 | * | ||
251 | * @ORM\Column(name="origin_url", type="text", nullable=true) | ||
252 | * | ||
253 | * @Groups({"entries_for_user", "export_all"}) | ||
254 | */ | ||
255 | private $originUrl; | ||
256 | |||
257 | /* | 302 | /* |
258 | * @param User $user | 303 | * @param User $user |
259 | */ | 304 | */ |
@@ -307,6 +352,7 @@ class Entry | |||
307 | public function setUrl($url) | 352 | public function setUrl($url) |
308 | { | 353 | { |
309 | $this->url = $url; | 354 | $this->url = $url; |
355 | $this->hashedUrl = UrlHasher::hashUrl($url); | ||
310 | 356 | ||
311 | return $this; | 357 | return $this; |
312 | } | 358 | } |
@@ -336,6 +382,44 @@ class Entry | |||
336 | } | 382 | } |
337 | 383 | ||
338 | /** | 384 | /** |
385 | * update isArchived and archive_at fields. | ||
386 | * | ||
387 | * @param bool $isArchived | ||
388 | * | ||
389 | * @return Entry | ||
390 | */ | ||
391 | public function updateArchived($isArchived = false) | ||
392 | { | ||
393 | $this->setArchived($isArchived); | ||
394 | $this->setArchivedAt(null); | ||
395 | if ($this->isArchived()) { | ||
396 | $this->setArchivedAt(new \DateTime()); | ||
397 | } | ||
398 | |||
399 | return $this; | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * @return \DateTime|null | ||
404 | */ | ||
405 | public function getArchivedAt() | ||
406 | { | ||
407 | return $this->archivedAt; | ||
408 | } | ||
409 | |||
410 | /** | ||
411 | * @param \DateTime|null $archivedAt | ||
412 | * | ||
413 | * @return Entry | ||
414 | */ | ||
415 | public function setArchivedAt($archivedAt = null) | ||
416 | { | ||
417 | $this->archivedAt = $archivedAt; | ||
418 | |||
419 | return $this; | ||
420 | } | ||
421 | |||
422 | /** | ||
339 | * Get isArchived. | 423 | * Get isArchived. |
340 | * | 424 | * |
341 | * @return bool | 425 | * @return bool |
@@ -357,7 +441,7 @@ class Entry | |||
357 | 441 | ||
358 | public function toggleArchive() | 442 | public function toggleArchive() |
359 | { | 443 | { |
360 | $this->isArchived = $this->isArchived() ^ 1; | 444 | $this->updateArchived($this->isArchived() ^ 1); |
361 | 445 | ||
362 | return $this; | 446 | return $this; |
363 | } | 447 | } |
@@ -466,8 +550,6 @@ class Entry | |||
466 | * Set created_at. | 550 | * Set created_at. |
467 | * Only used when importing data from an other service. | 551 | * Only used when importing data from an other service. |
468 | * | 552 | * |
469 | * @param \DateTime $createdAt | ||
470 | * | ||
471 | * @return Entry | 553 | * @return Entry |
472 | */ | 554 | */ |
473 | public function setCreatedAt(\DateTime $createdAt) | 555 | public function setCreatedAt(\DateTime $createdAt) |
@@ -539,9 +621,6 @@ class Entry | |||
539 | return $this->annotations; | 621 | return $this->annotations; |
540 | } | 622 | } |
541 | 623 | ||
542 | /** | ||
543 | * @param Annotation $annotation | ||
544 | */ | ||
545 | public function setAnnotation(Annotation $annotation) | 624 | public function setAnnotation(Annotation $annotation) |
546 | { | 625 | { |
547 | $this->annotations[] = $annotation; | 626 | $this->annotations[] = $annotation; |
@@ -618,9 +697,6 @@ class Entry | |||
618 | return $data; | 697 | return $data; |
619 | } | 698 | } |
620 | 699 | ||
621 | /** | ||
622 | * @param Tag $tag | ||
623 | */ | ||
624 | public function addTag(Tag $tag) | 700 | public function addTag(Tag $tag) |
625 | { | 701 | { |
626 | if ($this->tags->contains($tag)) { | 702 | if ($this->tags->contains($tag)) { |
@@ -641,8 +717,6 @@ class Entry | |||
641 | 717 | ||
642 | /** | 718 | /** |
643 | * Remove the given tag from the entry (if the tag is associated). | 719 | * Remove the given tag from the entry (if the tag is associated). |
644 | * | ||
645 | * @param Tag $tag | ||
646 | */ | 720 | */ |
647 | public function removeTag(Tag $tag) | 721 | public function removeTag(Tag $tag) |
648 | { | 722 | { |
@@ -714,7 +788,20 @@ class Entry | |||
714 | } | 788 | } |
715 | 789 | ||
716 | /** | 790 | /** |
717 | * @return string | 791 | * Format the entry language to a valid html lang attribute. |
792 | */ | ||
793 | public function getHTMLLanguage() | ||
794 | { | ||
795 | $parsedLocale = \Locale::parseLocale($this->getLanguage()); | ||
796 | $lang = ''; | ||
797 | $lang .= $parsedLocale['language'] ?? ''; | ||
798 | $lang .= isset($parsedLocale['region']) ? '-' . $parsedLocale['region'] : ''; | ||
799 | |||
800 | return $lang; | ||
801 | } | ||
802 | |||
803 | /** | ||
804 | * @return string|null | ||
718 | */ | 805 | */ |
719 | public function getUid() | 806 | public function getUid() |
720 | { | 807 | { |
@@ -790,8 +877,6 @@ class Entry | |||
790 | } | 877 | } |
791 | 878 | ||
792 | /** | 879 | /** |
793 | * @param \Datetime $publishedAt | ||
794 | * | ||
795 | * @return Entry | 880 | * @return Entry |
796 | */ | 881 | */ |
797 | public function setPublishedAt(\Datetime $publishedAt) | 882 | public function setPublishedAt(\Datetime $publishedAt) |
@@ -864,4 +949,49 @@ class Entry | |||
864 | { | 949 | { |
865 | return $this->originUrl; | 950 | return $this->originUrl; |
866 | } | 951 | } |
952 | |||
953 | /** | ||
954 | * Set given url. | ||
955 | * | ||
956 | * @param string $givenUrl | ||
957 | * | ||
958 | * @return Entry | ||
959 | */ | ||
960 | public function setGivenUrl($givenUrl) | ||
961 | { | ||
962 | $this->givenUrl = $givenUrl; | ||
963 | $this->hashedGivenUrl = UrlHasher::hashUrl($givenUrl); | ||
964 | |||
965 | return $this; | ||
966 | } | ||
967 | |||
968 | /** | ||
969 | * Get given url. | ||
970 | * | ||
971 | * @return string | ||
972 | */ | ||
973 | public function getGivenUrl() | ||
974 | { | ||
975 | return $this->givenUrl; | ||
976 | } | ||
977 | |||
978 | /** | ||
979 | * @return string | ||
980 | */ | ||
981 | public function getHashedUrl() | ||
982 | { | ||
983 | return $this->hashedUrl; | ||
984 | } | ||
985 | |||
986 | /** | ||
987 | * @param mixed $hashedUrl | ||
988 | * | ||
989 | * @return Entry | ||
990 | */ | ||
991 | public function setHashedUrl($hashedUrl) | ||
992 | { | ||
993 | $this->hashedUrl = $hashedUrl; | ||
994 | |||
995 | return $this; | ||
996 | } | ||
867 | } | 997 | } |