From 52fa9645ed8edd4a630e4d7c3382680863b9039d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sat, 8 May 2021 04:51:24 +0200 Subject: [PATCH] Add preUpdate life cycle callback --- Entity/User.php | 11 +++++++++++ Resources/config/doctrine/User.orm.yml | 2 ++ 2 files changed, 13 insertions(+) diff --git a/Entity/User.php b/Entity/User.php index 6d10f33..5fc9217 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -400,6 +400,17 @@ class User implements UserInterface, \Serializable { return $this->active; } + /** + * {@inheritdoc} + */ + public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $eventArgs) { + //Check that we have an user instance + if (($user = $eventArgs->getEntity()) instanceof User) { + //Set updated value + $user->setUpdated(new \DateTime('now')); + } + } + /** * Returns a string representation of the user * diff --git a/Resources/config/doctrine/User.orm.yml b/Resources/config/doctrine/User.orm.yml index a621be7..29755a5 100644 --- a/Resources/config/doctrine/User.orm.yml +++ b/Resources/config/doctrine/User.orm.yml @@ -43,3 +43,5 @@ Rapsys\UserBundle\Entity\User: #see if usefull: https://stackoverflow.com/questions/34523699/how-to-extend-doctrine-entity-in-another-bundle # joinTable: # name: groups_users + lifecycleCallbacks: + preUpdate: ['preUpdate'] -- 2.41.1