From 927c9e796ff6fad2bf82a965234f52932cdee657 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 6 Jul 2017 09:00:37 +0200 Subject: Add EntityTimestampsTrait to handle dates Refactorize timestamps() method to avoid re-writing it on each entity --- src/Wallabag/CoreBundle/Entity/Entry.php | 16 +++------------- src/Wallabag/CoreBundle/Entity/SiteCredential.php | 13 +++---------- 2 files changed, 6 insertions(+), 23 deletions(-) (limited to 'src/Wallabag/CoreBundle/Entity') diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index cba72d31..61d01bdc 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -12,6 +12,7 @@ use JMS\Serializer\Annotation\VirtualProperty; use JMS\Serializer\Annotation\XmlRoot; use Symfony\Component\Validator\Constraints as Assert; use Wallabag\AnnotationBundle\Entity\Annotation; +use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; use Wallabag\UserBundle\Entity\User; /** @@ -32,6 +33,8 @@ use Wallabag\UserBundle\Entity\User; */ class Entry { + use EntityTimestampsTrait; + /** @Serializer\XmlAttribute */ /** * @var int @@ -472,19 +475,6 @@ class Entry return $this->updatedAt; } - /** - * @ORM\PrePersist - * @ORM\PreUpdate - */ - public function timestamps() - { - if (null === $this->createdAt) { - $this->createdAt = new \DateTime(); - } - - $this->updatedAt = new \DateTime(); - } - /** * @return ArrayCollection */ diff --git a/src/Wallabag/CoreBundle/Entity/SiteCredential.php b/src/Wallabag/CoreBundle/Entity/SiteCredential.php index 4d6557c5..ac714359 100644 --- a/src/Wallabag/CoreBundle/Entity/SiteCredential.php +++ b/src/Wallabag/CoreBundle/Entity/SiteCredential.php @@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; +use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; use Wallabag\UserBundle\Entity\User; /** @@ -15,6 +16,8 @@ use Wallabag\UserBundle\Entity\User; */ class SiteCredential { + use EntityTimestampsTrait; + /** * @var int * @@ -182,14 +185,4 @@ class SiteCredential { return $this->user; } - - /** - * @ORM\PrePersist - */ - public function timestamps() - { - if (null === $this->createdAt) { - $this->createdAt = new \DateTime(); - } - } } -- cgit v1.2.3