diff options
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 16 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/SiteCredential.php | 13 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php | 24 |
3 files changed, 30 insertions, 23 deletions
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; | |||
12 | use JMS\Serializer\Annotation\XmlRoot; | 12 | 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\UserBundle\Entity\User; | 16 | use Wallabag\UserBundle\Entity\User; |
16 | 17 | ||
17 | /** | 18 | /** |
@@ -32,6 +33,8 @@ use Wallabag\UserBundle\Entity\User; | |||
32 | */ | 33 | */ |
33 | class Entry | 34 | class Entry |
34 | { | 35 | { |
36 | use EntityTimestampsTrait; | ||
37 | |||
35 | /** @Serializer\XmlAttribute */ | 38 | /** @Serializer\XmlAttribute */ |
36 | /** | 39 | /** |
37 | * @var int | 40 | * @var int |
@@ -473,19 +476,6 @@ class Entry | |||
473 | } | 476 | } |
474 | 477 | ||
475 | /** | 478 | /** |
476 | * @ORM\PrePersist | ||
477 | * @ORM\PreUpdate | ||
478 | */ | ||
479 | public function timestamps() | ||
480 | { | ||
481 | if (null === $this->createdAt) { | ||
482 | $this->createdAt = new \DateTime(); | ||
483 | } | ||
484 | |||
485 | $this->updatedAt = new \DateTime(); | ||
486 | } | ||
487 | |||
488 | /** | ||
489 | * @return ArrayCollection<Annotation> | 479 | * @return ArrayCollection<Annotation> |
490 | */ | 480 | */ |
491 | public function getAnnotations() | 481 | public function getAnnotations() |
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; | |||
4 | 4 | ||
5 | use Doctrine\ORM\Mapping as ORM; | 5 | use Doctrine\ORM\Mapping as ORM; |
6 | use Symfony\Component\Validator\Constraints as Assert; | 6 | use Symfony\Component\Validator\Constraints as Assert; |
7 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; | ||
7 | use Wallabag\UserBundle\Entity\User; | 8 | use Wallabag\UserBundle\Entity\User; |
8 | 9 | ||
9 | /** | 10 | /** |
@@ -15,6 +16,8 @@ use Wallabag\UserBundle\Entity\User; | |||
15 | */ | 16 | */ |
16 | class SiteCredential | 17 | class SiteCredential |
17 | { | 18 | { |
19 | use EntityTimestampsTrait; | ||
20 | |||
18 | /** | 21 | /** |
19 | * @var int | 22 | * @var int |
20 | * | 23 | * |
@@ -182,14 +185,4 @@ class SiteCredential | |||
182 | { | 185 | { |
183 | return $this->user; | 186 | return $this->user; |
184 | } | 187 | } |
185 | |||
186 | /** | ||
187 | * @ORM\PrePersist | ||
188 | */ | ||
189 | public function timestamps() | ||
190 | { | ||
191 | if (null === $this->createdAt) { | ||
192 | $this->createdAt = new \DateTime(); | ||
193 | } | ||
194 | } | ||
195 | } | 188 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php b/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php new file mode 100644 index 00000000..1b1ff54a --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php | |||
@@ -0,0 +1,24 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Doctrine\ORM\Mapping as ORM; | ||
6 | |||
7 | /** | ||
8 | * Trait to handle created & updated date of an Entity. | ||
9 | */ | ||
10 | trait EntityTimestampsTrait | ||
11 | { | ||
12 | /** | ||
13 | * @ORM\PrePersist | ||
14 | * @ORM\PreUpdate | ||
15 | */ | ||
16 | public function timestamps() | ||
17 | { | ||
18 | if (null === $this->createdAt) { | ||
19 | $this->createdAt = new \DateTime(); | ||
20 | } | ||
21 | |||
22 | $this->updatedAt = new \DateTime(); | ||
23 | } | ||
24 | } | ||