Rapsys Git
/
userbundle
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c0d7b2e
)
Add doctrine preUpdate lifecycleCallbacks on civility and group
author
Raphaël Gertz
<git@rapsys.eu>
Mon, 23 Aug 2021 07:07:47 +0000
(09:07 +0200)
committer
Raphaël Gertz
<git@rapsys.eu>
Mon, 23 Aug 2021 07:07:47 +0000
(09:07 +0200)
Entity/Civility.php
patch
|
blob
|
history
Entity/Group.php
patch
|
blob
|
history
Resources/config/doctrine/Civility.orm.yml
patch
|
blob
|
history
Resources/config/doctrine/Group.orm.yml
patch
|
blob
|
history
diff --git
a/Entity/Civility.php
b/Entity/Civility.php
index f3509194542f2ac3711badf984c9d172b5c61c59..4d2671a1dee821fd8e44bd25fa1288dd52f24e64 100644
(file)
--- a/
Entity/Civility.php
+++ b/
Entity/Civility.php
@@
-12,6
+12,7
@@
namespace Rapsys\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
namespace Rapsys\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Event\PreUpdateEventArgs;
use Rapsys\UserBundle\Entity\User;
use Rapsys\UserBundle\Entity\User;
@@
-160,6
+161,17
@@
class Civility {
return $this->users;
}
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
*
/**
* Returns a string representation of the title
*
diff --git
a/Entity/Group.php
b/Entity/Group.php
index d7ca3c7e0c56651406fa793711ced9bfa040f61e..188e1bce5c188e851047706041cb81285040687d 100644
(file)
--- a/
Entity/Group.php
+++ b/
Entity/Group.php
@@
-12,6
+12,7
@@
namespace Rapsys\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
namespace Rapsys\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Event\PreUpdateEventArgs;
use Rapsys\UserBundle\Entity\User;
use Rapsys\UserBundle\Entity\User;
@@
-160,6
+161,17
@@
class Group {
return $this->users;
}
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
*
/**
* Returns a string representation of the group
*
diff --git
a/Resources/config/doctrine/Civility.orm.yml
b/Resources/config/doctrine/Civility.orm.yml
index a175fa8b04daadc7612ae26428c663f1e888a4e5..6ed794449332692be0da03e59e4afc1982ac6405 100644
(file)
--- 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
# 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 af56dbeddfa1f00fafe02cf62a28c57fc6415a58..ee28e6cb2b8ee8fc3da3084661609d498cd95b76 100644
(file)
--- 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
# users:
# targetEntity: User
# mappedBy: groups
+ lifecycleCallbacks:
+ preUpdate: ['preUpdate']