]> Raphaël G. Git Repositories - userbundle/commitdiff
Add doctrine preUpdate lifecycleCallbacks on civility and group
authorRaphaël Gertz <git@rapsys.eu>
Mon, 23 Aug 2021 07:07:47 +0000 (09:07 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Mon, 23 Aug 2021 07:07:47 +0000 (09:07 +0200)
Entity/Civility.php
Entity/Group.php
Resources/config/doctrine/Civility.orm.yml
Resources/config/doctrine/Group.orm.yml

index f3509194542f2ac3711badf984c9d172b5c61c59..4d2671a1dee821fd8e44bd25fa1288dd52f24e64 100644 (file)
@@ -12,6 +12,7 @@
 namespace Rapsys\UserBundle\Entity;
 
 use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Event\PreUpdateEventArgs;
 
 use Rapsys\UserBundle\Entity\User;
 
@@ -160,6 +161,17 @@ class Civility {
                return $this->users;
        }
 
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs) {
+               //Check that we have a civility instance
+               if (($user = $eventArgs->getEntity()) instanceof Civility) {
+                       //Set updated value
+                       $user->setUpdated(new \DateTime('now'));
+               }
+       }
+
        /**
         * Returns a string representation of the title
         *
index d7ca3c7e0c56651406fa793711ced9bfa040f61e..188e1bce5c188e851047706041cb81285040687d 100644 (file)
@@ -12,6 +12,7 @@
 namespace Rapsys\UserBundle\Entity;
 
 use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Event\PreUpdateEventArgs;
 
 use Rapsys\UserBundle\Entity\User;
 
@@ -160,6 +161,17 @@ class Group {
                return $this->users;
        }
 
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs) {
+               //Check that we have a group instance
+               if (($user = $eventArgs->getEntity()) instanceof Group) {
+                       //Set updated value
+                       $user->setUpdated(new \DateTime('now'));
+               }
+       }
+
        /**
         * Returns a string representation of the group
         *
index a175fa8b04daadc7612ae26428c663f1e888a4e5..6ed794449332692be0da03e59e4afc1982ac6405 100644 (file)
@@ -19,3 +19,5 @@ Rapsys\UserBundle\Entity\Civility:
 #        users:
 #            targetEntity: User
 #            mappedBy: title
+    lifecycleCallbacks:
+        preUpdate: ['preUpdate']
index af56dbeddfa1f00fafe02cf62a28c57fc6415a58..ee28e6cb2b8ee8fc3da3084661609d498cd95b76 100644 (file)
@@ -19,3 +19,5 @@ Rapsys\UserBundle\Entity\Group:
 #        users:
 #            targetEntity: User
 #            mappedBy: groups
+    lifecycleCallbacks:
+        preUpdate: ['preUpdate']