From: Raphaƫl Gertz Date: Mon, 23 Aug 2021 07:07:47 +0000 (+0200) Subject: Add doctrine preUpdate lifecycleCallbacks on civility and group X-Git-Tag: 0.2.0~39 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/ea9b00a8025f8bbe7a1c28399f7538bea6d60a2c?ds=sidebyside Add doctrine preUpdate lifecycleCallbacks on civility and group --- diff --git a/Entity/Civility.php b/Entity/Civility.php index f350919..4d2671a 100644 --- a/Entity/Civility.php +++ b/Entity/Civility.php @@ -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 * diff --git a/Entity/Group.php b/Entity/Group.php index d7ca3c7..188e1bc 100644 --- a/Entity/Group.php +++ b/Entity/Group.php @@ -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 * diff --git a/Resources/config/doctrine/Civility.orm.yml b/Resources/config/doctrine/Civility.orm.yml index a175fa8..6ed7944 100644 --- a/Resources/config/doctrine/Civility.orm.yml +++ b/Resources/config/doctrine/Civility.orm.yml @@ -19,3 +19,5 @@ Rapsys\UserBundle\Entity\Civility: # users: # targetEntity: User # mappedBy: title + lifecycleCallbacks: + preUpdate: ['preUpdate'] diff --git a/Resources/config/doctrine/Group.orm.yml b/Resources/config/doctrine/Group.orm.yml index af56dbe..ee28e6c 100644 --- a/Resources/config/doctrine/Group.orm.yml +++ b/Resources/config/doctrine/Group.orm.yml @@ -19,3 +19,5 @@ Rapsys\UserBundle\Entity\Group: # users: # targetEntity: User # mappedBy: groups + lifecycleCallbacks: + preUpdate: ['preUpdate']