From fdd26decb6fd7be0c62bbd190e620378a1021567 Mon Sep 17 00:00:00 2001 From: Benjamin Vison Date: Sun, 27 May 2018 19:58:55 -0400 Subject: [PATCH] Added entity state verification --- EventSubscriber/DoctrineEventSubscriber.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/EventSubscriber/DoctrineEventSubscriber.php b/EventSubscriber/DoctrineEventSubscriber.php index 8e2dac6..ae38a46 100755 --- a/EventSubscriber/DoctrineEventSubscriber.php +++ b/EventSubscriber/DoctrineEventSubscriber.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\UnitOfWork; use NTI\SyncBundle\Annotations\SyncEntity; use NTI\SyncBundle\Annotations\SyncParent; use NTI\SyncBundle\Entity\SyncMapping; @@ -93,13 +94,17 @@ private function processEntity(EntityManagerInterface $em, $entity) $em->persist($syncState); } $syncState->setTimestamp($timestamp); - $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(SyncState::class), $syncState); + if($uow->getEntityState($syncState) == UnitOfWork::STATE_MANAGED) { + $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(SyncState::class), $syncState); + } } // Check if this class itself has a lastTimestamp if(method_exists($entity, 'setLastTimestamp')) { $entity->setLastTimestamp($timestamp); - $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity); + if($uow->getEntityState($entity) == UnitOfWork::STATE_MANAGED) { + $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity); + } } // Notify relationships