From f7965f8d6ad658ce22837f04232a1a474104f542 Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Wed, 6 May 2015 14:02:05 -0600 Subject: [PATCH] Move flush to fire after event triggering. --- src/Server/Resource/DoctrineResource.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Server/Resource/DoctrineResource.php b/src/Server/Resource/DoctrineResource.php index fb9aed91..d5e87a60 100644 --- a/src/Server/Resource/DoctrineResource.php +++ b/src/Server/Resource/DoctrineResource.php @@ -312,12 +312,14 @@ public function create($data) } $this->getObjectManager()->persist($entity); - $this->getObjectManager()->flush(); + $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_CREATE_POST, $entity); if ($results->last() instanceof ApiProblem) { return $results->last(); } + $this->getObjectManager()->flush(); + return $entity; } @@ -343,13 +345,14 @@ public function delete($id) } $this->getObjectManager()->remove($entity); - $this->getObjectManager()->flush(); $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_DELETE_POST, $entity); if ($results->last() instanceof ApiProblem) { return $results->last(); } + $this->getObjectManager()->flush(); + return true; } @@ -545,20 +548,21 @@ public function patch($id, $data) } // @codeCoverageIgnoreEnd - // Hydrate entity with patched data - $this->getHydrator()->hydrate((array) $data, $entity); - $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_PATCH_PRE, $entity); if ($results->last() instanceof ApiProblem) { return $results->last(); } - $this->getObjectManager()->flush(); + // Hydrate entity with patched data + $this->getHydrator()->hydrate((array) $data, $entity); + $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_PATCH_POST, $entity); if ($results->last() instanceof ApiProblem) { return $results->last(); } + $this->getObjectManager()->flush(); + return $entity; } @@ -591,19 +595,20 @@ public function update($id, $data) } // @codeCoverageIgnoreEnd - $this->getHydrator()->hydrate((array) $data, $entity); - $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_UPDATE_PRE, $entity); if ($results->last() instanceof ApiProblem) { return $results->last(); } - $this->getObjectManager()->flush(); + $this->getHydrator()->hydrate((array) $data, $entity); + $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_UPDATE_POST, $entity); if ($results->last() instanceof ApiProblem) { return $results->last(); } + $this->getObjectManager()->flush(); + return $entity; }