X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FEntry.php;h=3cf9ac1a3b061f2928350119bba0be128e66c431;hb=1093e979ff49f9072c30d1d576c6adf1f8e76bdf;hp=84981414a639e81da28d209758d36bd6fefb7787;hpb=af95c09c800e8aa8ef4af053f35d506136ecd685;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 84981414..3cf9ac1a 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -19,7 +19,11 @@ use Wallabag\AnnotationBundle\Entity\Annotation; * * @XmlRoot("entry") * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") - * @ORM\Table(name="`entry`") + * @ORM\Table( + * name="`entry`", + * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, + * indexes={@ORM\Index(name="created_at", columns={"created_at"})} + * ) * @ORM\HasLifecycleCallbacks() * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") */ @@ -37,6 +41,15 @@ class Entry */ private $id; + /** + * @var string + * + * @ORM\Column(name="uuid", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $uuid; + /** * @var string * @@ -88,20 +101,20 @@ class Entry private $content; /** - * @var date + * @var \DateTime * * @ORM\Column(name="created_at", type="datetime") * - * @Groups({"export_all"}) + * @Groups({"entries_for_user", "export_all"}) */ private $createdAt; /** - * @var date + * @var \DateTime * * @ORM\Column(name="updated_at", type="datetime") * - * @Groups({"export_all"}) + * @Groups({"entries_for_user", "export_all"}) */ private $updatedAt; @@ -167,6 +180,15 @@ class Entry */ private $isPublic; + /** + * @var string + * + * @ORM\Column(name="http_status", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $httpStatus; + /** * @Exclude * @@ -178,9 +200,15 @@ class Entry /** * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) - * @ORM\JoinTable - * - * @Groups({"entries_for_user", "export_all"}) + * @ORM\JoinTable( + * name="entry_tag", + * joinColumns={ + * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade") + * }, + * inverseJoinColumns={ + * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade") + * } + * ) */ private $tags; @@ -393,7 +421,22 @@ class Entry } /** - * @return string + * Set created_at. + * Only used when importing data from an other service. + * + * @param \DateTime $createdAt + * + * @return Entry + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + + return $this; + } + + /** + * @return \DateTime */ public function getCreatedAt() { @@ -401,7 +444,7 @@ class Entry } /** - * @return string + * @return \DateTime */ public function getUpdatedAt() { @@ -509,6 +552,21 @@ class Entry return $this->tags; } + /** + * @VirtualProperty + * @SerializedName("tags") + * @Groups({"entries_for_user", "export_all"}) + */ + public function getSerializedTags() + { + $data = []; + foreach ($this->tags as $tag) { + $data[] = $tag->getLabel(); + } + + return $data; + } + /** * @param Tag $tag */ @@ -526,13 +584,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 +645,57 @@ class Entry { return $this->language; } + + /** + * @return string + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * @param string $uuid + * + * @return Entry + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + + return $this; + } + + public function generateUuid() + { + if (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; + } + + /** + * @return int + */ + public function getHttpStatus() + { + return $this->httpStatus; + } + + /** + * @param int $httpStatus + * + * @return Entry + */ + public function setHttpStatus($httpStatus) + { + $this->httpStatus = $httpStatus; + + return $this; + } }