Skip to content

Commit

Permalink
Improved PrePersist for timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mecanik committed Oct 23, 2023
1 parent 1682875 commit 2e28d19
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Entity/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public function onPrePersist()
{
if (null === $this->getCreatedAt()) {
$this->setCreatedAt(new \DateTimeImmutable('now'));
}

if ($this->getUpdatedAt() == null) {
$this->setUpdatedAt(new \DateTimeImmutable('now'));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ public function onPrePersist()
{
if (null === $this->getCreatedAt()) {
$this->setCreatedAt(new \DateTimeImmutable('now'));
}

if ($this->getUpdatedAt() == null) {
$this->setUpdatedAt(new \DateTimeImmutable('now'));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public function onPrePersist()
{
if (null === $this->getCreatedAt()) {
$this->setCreatedAt(new \DateTimeImmutable('now'));
}

if ($this->getUpdatedAt() == null) {
$this->setUpdatedAt(new \DateTimeImmutable('now'));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ public function onPrePersist()
{
if (null === $this->getCreatedAt()) {
$this->setCreatedAt(new \DateTimeImmutable('now'));
}

if ($this->getUpdatedAt() == null) {
$this->setUpdatedAt(new \DateTimeImmutable('now'));
}
}

Expand Down

0 comments on commit 2e28d19

Please sign in to comment.