From: Raphaƫl Gertz Date: Sat, 8 May 2021 02:53:13 +0000 (+0200) Subject: Add preUpdate life cycle callback X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/2ef0c16b8202ff4e360b7dc31fc3e24336303bd5 Add preUpdate life cycle callback --- diff --git a/Entity/Snippet.php b/Entity/Snippet.php index 20a1940..f8ae7d2 100644 --- a/Entity/Snippet.php +++ b/Entity/Snippet.php @@ -319,4 +319,15 @@ class Snippet { public function getUser() { return $this->user; } + + /** + * {@inheritdoc} + */ + public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $eventArgs) { + //Check that we have an snippet instance + if (($snippet = $eventArgs->getEntity()) instanceof Snippet) { + //Set updated value + $snippet->setUpdated(new \DateTime('now')); + } + } } diff --git a/Resources/config/doctrine/Snippet.orm.yml b/Resources/config/doctrine/Snippet.orm.yml index 4b172d6..85253f3 100644 --- a/Resources/config/doctrine/Snippet.orm.yml +++ b/Resources/config/doctrine/Snippet.orm.yml @@ -52,3 +52,5 @@ Rapsys\AirBundle\Entity\Snippet: uniqueConstraints: locale_location_user: columns: [ locale, location_id, user_id ] + lifecycleCallbacks: + preUpdate: ['preUpdate']