Add EntityTimestampsTrait to handle dates

Refactorize timestamps() method to avoid re-writing it on each entity
This commit is contained in:
Jeremy Benoist
2017-07-06 09:00:37 +02:00
parent b5d7eb148c
commit 927c9e796f
5 changed files with 36 additions and 48 deletions

View File

@ -10,6 +10,7 @@ use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\VirtualProperty;
use Symfony\Component\Validator\Constraints as Assert;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
use Wallabag\UserBundle\Entity\User;
/**
@ -22,6 +23,8 @@ use Wallabag\UserBundle\Entity\User;
*/
class Annotation
{
use EntityTimestampsTrait;
/**
* @var int
*
@ -133,18 +136,6 @@ class Annotation
return $this->text;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function timestamps()
{
if (null === $this->createdAt) {
$this->createdAt = new \DateTime();
}
$this->updatedAt = new \DateTime();
}
/**
* Get created.
*