55namespace PhpList \Core \Domain \Messaging \Model ;
66
77use DateTime ;
8+ use DateTimeImmutable ;
89use Doctrine \Common \Collections \ArrayCollection ;
910use Doctrine \Common \Collections \Collection ;
1011use Doctrine \ORM \Mapping as ORM ;
@@ -31,8 +32,8 @@ class Message implements DomainModel, Identity, ModificationDate, OwnableInterfa
3132 #[ORM \GeneratedValue]
3233 private ?int $ id = null ;
3334
34- #[ORM \Column(name: 'modified ' , type: 'datetime ' )]
35- private ?DateTime $ updatedAt = null ;
35+ #[ORM \Column(name: 'modified ' , type: 'datetime_immutable ' , nullable: false )]
36+ private ?DateTimeImmutable $ updatedAt = null ;
3637
3738 #[ORM \Embedded(class: MessageFormat::class, columnPrefix: false )]
3839 private MessageFormat $ format ;
@@ -88,18 +89,27 @@ public function getId(): ?int
8889 return $ this ->id ;
8990 }
9091
92+ /** @SuppressWarnings(PHPMD.StaticAccess) */
9193 public function getUpdatedAt (): ?DateTime
9294 {
93- return $ this ->updatedAt ;
95+ if (null === $ this ->updatedAt ) {
96+ return null ;
97+ }
98+
99+ return DateTime::createFromImmutable ($ this ->updatedAt );
94100 }
95101
96102 #[ORM \PrePersist]
97- #[ORM \PreUpdate]
98- public function updateUpdatedAt (): DomainModel
103+ public function setCreatedTimestamps (): void
99104 {
100- $ this ->updatedAt = new DateTime ();
105+ $ this ->metadata ->setEntered (new DateTime ());
106+ }
101107
102- return $ this ;
108+ #[ORM \PrePersist]
109+ #[ORM \PreUpdate]
110+ public function touchUpdatedTimestamp (): void
111+ {
112+ $ this ->updatedAt = new DateTimeImmutable ();
103113 }
104114
105115 public function getFormat (): MessageFormat
0 commit comments