Refactorize timestamps() method to avoid re-writing it on each entity
use JMS\Serializer\Annotation\VirtualProperty;
use Symfony\Component\Validator\Constraints as Assert;
use Wallabag\CoreBundle\Entity\Entry;
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;
/**
use Wallabag\UserBundle\Entity\User;
/**
+ use EntityTimestampsTrait;
+
- /**
- * @ORM\PrePersist
- * @ORM\PreUpdate
- */
- public function timestamps()
- {
- if (null === $this->createdAt) {
- $this->createdAt = new \DateTime();
- }
- $this->updatedAt = new \DateTime();
- }
-
use JMS\Serializer\Annotation\XmlRoot;
use Symfony\Component\Validator\Constraints as Assert;
use Wallabag\AnnotationBundle\Entity\Annotation;
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;
/**
use Wallabag\UserBundle\Entity\User;
/**
+ use EntityTimestampsTrait;
+
/** @Serializer\XmlAttribute */
/**
* @var int
/** @Serializer\XmlAttribute */
/**
* @var int
return $this->updatedAt;
}
return $this->updatedAt;
}
- /**
- * @ORM\PrePersist
- * @ORM\PreUpdate
- */
- public function timestamps()
- {
- if (null === $this->createdAt) {
- $this->createdAt = new \DateTime();
- }
-
- $this->updatedAt = new \DateTime();
- }
-
/**
* @return ArrayCollection<Annotation>
*/
/**
* @return ArrayCollection<Annotation>
*/
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
+use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
use Wallabag\UserBundle\Entity\User;
/**
use Wallabag\UserBundle\Entity\User;
/**
*/
class SiteCredential
{
*/
class SiteCredential
{
+ use EntityTimestampsTrait;
+
-
- /**
- * @ORM\PrePersist
- */
- public function timestamps()
- {
- if (null === $this->createdAt) {
- $this->createdAt = new \DateTime();
- }
- }
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Helper;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Trait to handle created & updated date of an Entity.
+ */
+trait EntityTimestampsTrait
+{
+ /**
+ * @ORM\PrePersist
+ * @ORM\PreUpdate
+ */
+ public function timestamps()
+ {
+ if (null === $this->createdAt) {
+ $this->createdAt = new \DateTime();
+ }
+
+ $this->updatedAt = new \DateTime();
+ }
+}
use Wallabag\ApiBundle\Entity\Client;
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\ApiBundle\Entity\Client;
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\Entry;
+use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
*/
class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface
{
*/
class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface
{
+ use EntityTimestampsTrait;
+
/** @Serializer\XmlAttribute */
/**
* @var int
/** @Serializer\XmlAttribute */
/**
* @var int
$this->roles = ['ROLE_USER'];
}
$this->roles = ['ROLE_USER'];
}
- /**
- * @ORM\PrePersist
- * @ORM\PreUpdate
- */
- public function timestamps()
- {
- if (null === $this->createdAt) {
- $this->createdAt = new \DateTime();
- }
-
- $this->updatedAt = new \DateTime();
- }
-