diff --git a/src/Entity/NamedDBElement.php b/src/Entity/NamedDBElement.php index 0b832855..de57d911 100644 --- a/src/Entity/NamedDBElement.php +++ b/src/Entity/NamedDBElement.php @@ -29,6 +29,7 @@ use Doctrine\ORM\Mapping as ORM; * All subclasses of this class have an attribute "name". * * @ORM\MappedSuperclass() + * @ORM\HasLifecycleCallbacks() */ abstract class NamedDBElement extends DBElement { @@ -107,4 +108,23 @@ abstract class NamedDBElement extends DBElement return $this; } + /****************************************************************************** + * + * Helpers + * + ******************************************************************************/ + + /** + * Helper for updating the timestamp. It is automatically called by doctrine before persisting. + * @ORM\PrePersist + * @ORM\PreUpdate + */ + public function updatedTimestamps(): void + { + $this->lastModified = new \DateTime('now'); + if ($this->addedDate === null) { + $this->addedDate = new \DateTime('now'); + } + } + } \ No newline at end of file