|
5 | 5 | namespace RZ\Roadiz\Core\AbstractEntities; |
6 | 6 |
|
7 | 7 | use Doctrine\ORM\Mapping as ORM; |
8 | | -use JMS\Serializer\Annotation as Serializer; |
9 | | -use Symfony\Component\Serializer\Annotation as SymfonySerializer; |
10 | 8 |
|
11 | 9 | /** |
12 | 10 | * An AbstractEntity with datetime fields to keep track of time with your items. |
| 11 | + * |
| 12 | + * @deprecated since 2.6, use composition with DateTimedTrait instead. |
13 | 13 | */ |
14 | 14 | #[ |
15 | 15 | ORM\MappedSuperclass, |
|
18 | 18 | ORM\Index(columns: ['created_at']), |
19 | 19 | ORM\Index(columns: ['updated_at']), |
20 | 20 | ] |
21 | | -abstract class AbstractDateTimed extends AbstractEntity |
| 21 | +abstract class AbstractDateTimed extends AbstractEntity implements DateTimedInterface |
22 | 22 | { |
23 | | - #[ |
24 | | - ORM\Column(name: 'created_at', type: 'datetime', nullable: true), |
25 | | - Serializer\Groups(['timestamps']), |
26 | | - SymfonySerializer\Groups(['timestamps']), |
27 | | - ] |
28 | | - protected ?\DateTime $createdAt = null; |
29 | | - |
30 | | - #[ |
31 | | - ORM\Column(name: 'updated_at', type: 'datetime', nullable: true), |
32 | | - Serializer\Groups(['timestamps']), |
33 | | - SymfonySerializer\Groups(['timestamps']), |
34 | | - ] |
35 | | - protected ?\DateTime $updatedAt = null; |
36 | | - |
37 | | - public function getCreatedAt(): ?\DateTime |
38 | | - { |
39 | | - return $this->createdAt; |
40 | | - } |
41 | | - |
42 | | - /** |
43 | | - * @return $this |
44 | | - */ |
45 | | - public function setCreatedAt(?\DateTime $createdAt): self |
46 | | - { |
47 | | - $this->createdAt = $createdAt; |
48 | | - |
49 | | - return $this; |
50 | | - } |
51 | | - |
52 | | - public function getUpdatedAt(): ?\DateTime |
53 | | - { |
54 | | - return $this->updatedAt; |
55 | | - } |
56 | | - |
57 | | - /** |
58 | | - * @return $this |
59 | | - */ |
60 | | - public function setUpdatedAt(?\DateTime $updatedAt): self |
61 | | - { |
62 | | - $this->updatedAt = $updatedAt; |
63 | | - |
64 | | - return $this; |
65 | | - } |
66 | | - |
67 | | - protected function initAbstractDateTimed(): void |
68 | | - { |
69 | | - $this->setUpdatedAt(new \DateTime('now')); |
70 | | - $this->setCreatedAt(new \DateTime('now')); |
71 | | - } |
72 | | - |
73 | | - #[ORM\PreUpdate] |
74 | | - public function preUpdate(): void |
75 | | - { |
76 | | - $this->setUpdatedAt(new \DateTime('now')); |
77 | | - } |
78 | | - |
79 | | - #[ORM\PrePersist] |
80 | | - public function prePersist(): void |
81 | | - { |
82 | | - $this->setUpdatedAt(new \DateTime('now')); |
83 | | - $this->setCreatedAt(new \DateTime('now')); |
84 | | - } |
85 | | - |
86 | | - /** |
87 | | - * Set creation and update date to *now*. |
88 | | - * |
89 | | - * @return $this |
90 | | - */ |
91 | | - public function resetDates(): self |
92 | | - { |
93 | | - $this->setCreatedAt(new \DateTime('now')); |
94 | | - $this->setUpdatedAt(new \DateTime('now')); |
95 | | - |
96 | | - return $this; |
97 | | - } |
| 23 | + use DateTimedTrait; |
98 | 24 | } |
0 commit comments