Skip to content

Commit

Permalink
Added fix for bug when deleting entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Vison committed Jun 27, 2018
1 parent fdd26de commit a992791
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions EventSubscriber/DoctrineEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a992791

Please sign in to comment.