]> Raphaël G. Git Repositories - userbundle/commitdiff
Add preUpdate life cycle callback
authorRaphaël Gertz <git@rapsys.eu>
Sat, 8 May 2021 02:51:24 +0000 (04:51 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Sat, 8 May 2021 02:51:24 +0000 (04:51 +0200)
Entity/User.php
Resources/config/doctrine/User.orm.yml

index 6d10f33dd9be026fdc5f41eb4e4321db8e3389d2..5fc921719ad0294a4837f0e536e59c5b965a79c7 100644 (file)
@@ -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
         *
index a621be7abfd3b370de970a4a91e60324d3dc96f9..29755a580c9de3bc34def121df0f85eeb99f83c1 100644 (file)
@@ -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']