mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added Doctrine LifecycleCallback, so that entity timestamps are updated
When entity data is changed.
This commit is contained in:
parent
52acac3681
commit
a94a5690e1
1 changed files with 20 additions and 0 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue