From 0bb50873919a5dac542e00b47a22b965e1926228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Sat, 11 Mar 2023 15:28:00 +0100 Subject: [PATCH] Fill created datetime only if no date was provided beforehand --- src/Traits/Timestamp.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Traits/Timestamp.php b/src/Traits/Timestamp.php index 17ba250..c3c3332 100644 --- a/src/Traits/Timestamp.php +++ b/src/Traits/Timestamp.php @@ -48,16 +48,16 @@ public function getTimestamp(): DateTimeInterface } - #[ORM\PreUpdate] - public function onUpdate(): void + #[ORM\PrePersist] + public function onCreated(): void { - $this->modified = new DateTime; + $this->created ??= new DateTime; } - #[ORM\PrePersist] - public function onPersist(): void + #[ORM\PreUpdate] + public function onModified(): void { - $this->created = new DateTime; + $this->modified = new DateTime; } }