From 9fb10550fdb3dadf8dd5d6b2751c2d7c5e5e3f82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sat, 8 May 2021 04:53:13 +0200 Subject: [PATCH] Add preUpdate life cycle callback --- Entity/Snippet.php | 11 +++++++++++ Resources/config/doctrine/Snippet.orm.yml | 2 ++ 2 files changed, 13 insertions(+) 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'] -- 2.41.1