From 6366989147f689db11215a3ce9d4ae7408a6527f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samir=20Compr=C3=A9s?= Date: Mon, 16 Nov 2020 09:24:26 -0500 Subject: [PATCH] fix(Event Subscriber): setting createdOn field before fk field to avoid sending null createdOn to DB when fk exceptions happen --- src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php b/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php index 3b91406..3378d2c 100755 --- a/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php +++ b/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php @@ -468,7 +468,7 @@ protected function assoc(EntityManager $em, $association = null, $diff = false) } $meta = get_class($association); - $res = ['class' => $meta, 'typ' => $this->typ($meta), 'tbl' => null, 'label' => null]; + $res = ['class' => $meta, 'typ' => $this->typ($meta), 'tbl' => null, 'label' => null, 'createdOn' => new \DateTime()]; try { $meta = $em->getClassMetadata($meta); @@ -476,7 +476,6 @@ protected function assoc(EntityManager $em, $association = null, $diff = false) $em->getUnitOfWork()->initializeObject($association); // ensure that proxies are initialized $res['fk'] = $this->getUser() != null && $diff == false ? $this->getUser()->getId() : (string)$this->id($em, $association); $res['label'] = $this->label($em, $association, $diff); - $res['createdOn'] = new \DateTime(); } catch (\Exception $e) { $res['fk'] = (string) $association->getId(); }