Skip to content

Commit

Permalink
Added entity state verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Vison committed May 27, 2018
1 parent 0548505 commit fdd26de
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions EventSubscriber/DoctrineEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fdd26de

Please sign in to comment.