Added Doctrine LifecycleCallback, so that entity timestamps are updated

When entity data is changed.
This commit is contained in:
Jan Böhmer 2019-03-05 14:02:36 +01:00
parent 52acac3681
commit a94a5690e1

View file

@ -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');
}
}
}