From a992791c02eb273d08c2c7da1b05d86030f0eab9 Mon Sep 17 00:00:00 2001 From: Benjamin Vison Date: Wed, 27 Jun 2018 16:41:32 +0000 Subject: [PATCH] Added fix for bug when deleting entities --- EventSubscriber/DoctrineEventSubscriber.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/EventSubscriber/DoctrineEventSubscriber.php b/EventSubscriber/DoctrineEventSubscriber.php index ae38a46..c06d84d 100755 --- a/EventSubscriber/DoctrineEventSubscriber.php +++ b/EventSubscriber/DoctrineEventSubscriber.php @@ -49,8 +49,9 @@ public function onFlush(OnFlushEventArgs $args) } foreach ($uow->getScheduledEntityDeletions() as $entity) { - $this->processEntity($em, $entity); + $this->processEntity($em, $entity, true); $this->container->get('nti.sync')->addToDeleteSyncState(ClassUtils::getClass($entity), $entity->getId()); + } /** @var PersistentCollection $collectionUpdate */ @@ -63,14 +64,14 @@ public function onFlush(OnFlushEventArgs $args) /** @var PersistentCollection $collectionDeletion */ foreach($uow->getScheduledCollectionDeletions() as $collectionDeletion) { foreach($collectionDeletion as $entity) { - $this->processEntity($em, $entity); + $this->processEntity($em, $entity, true); $this->container->get('nti.sync')->addToDeleteSyncState(ClassUtils::getClass($entity), $entity->getId()); } } } - private function processEntity(EntityManagerInterface $em, $entity) + private function processEntity(EntityManagerInterface $em, $entity, $deleting = false) { $reflection = new \ReflectionClass(ClassUtils::getClass($entity)); @@ -100,11 +101,9 @@ private function processEntity(EntityManagerInterface $em, $entity) } // Check if this class itself has a lastTimestamp - if(method_exists($entity, 'setLastTimestamp')) { + if(!$deleting && method_exists($entity, 'setLastTimestamp')) { $entity->setLastTimestamp($timestamp); - if($uow->getEntityState($entity) == UnitOfWork::STATE_MANAGED) { - $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity); - } + $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity); } // Notify relationships