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

index 20a19401ffc2549f396be30f50e11fb54c483631..f8ae7d28fa4d4e124f7e71235101a2a793baf426 100644 (file)
@@ -319,4 +319,15 @@ class Snippet {
        public function getUser() {
                return $this->user;
        }
        public function getUser() {
                return $this->user;
        }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs  $eventArgs) {
+               //Check that we have an snippet instance
+               if (($snippet = $eventArgs->getEntity()) instanceof Snippet) {
+                       //Set updated value
+                       $snippet->setUpdated(new \DateTime('now'));
+               }
+       }
 }
 }
index 4b172d65073fdbf91545a1ccffcf147be0154d2a..85253f3232a182c8d28cc598ae9e96f208d051c7 100644 (file)
@@ -52,3 +52,5 @@ Rapsys\AirBundle\Entity\Snippet:
     uniqueConstraints:
         locale_location_user:
             columns: [ locale, location_id, user_id ]
     uniqueConstraints:
         locale_location_user:
             columns: [ locale, location_id, user_id ]
+    lifecycleCallbacks:
+        preUpdate: ['preUpdate']