Fix issue when using notify tracking policy with multiple flush on entity
This commit is contained in:
parent
5770459bfc
commit
866a424963
@ -324,7 +324,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute changes done since last commit.
|
// Compute changes done since last commit.
|
||||||
if ($entity === null) {
|
if (null === $entity) {
|
||||||
$this->computeChangeSets();
|
$this->computeChangeSets();
|
||||||
} elseif (is_object($entity)) {
|
} elseif (is_object($entity)) {
|
||||||
$this->computeSingleEntityChangeSet($entity);
|
$this->computeSingleEntityChangeSet($entity);
|
||||||
@ -414,17 +414,40 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
|
|
||||||
$this->dispatchPostFlushEvent();
|
$this->dispatchPostFlushEvent();
|
||||||
|
|
||||||
|
$this->postCommitClear($entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param null|object|array $entity
|
||||||
|
*/
|
||||||
|
private function postCommitClear($entity = null)
|
||||||
|
{
|
||||||
|
|
||||||
// Clear up
|
// Clear up
|
||||||
$this->entityInsertions =
|
$this->entityInsertions =
|
||||||
$this->entityUpdates =
|
$this->entityUpdates =
|
||||||
$this->entityDeletions =
|
$this->entityDeletions =
|
||||||
$this->extraUpdates =
|
$this->extraUpdates =
|
||||||
$this->entityChangeSets =
|
|
||||||
$this->collectionUpdates =
|
$this->collectionUpdates =
|
||||||
$this->collectionDeletions =
|
$this->collectionDeletions =
|
||||||
$this->visitedCollections =
|
$this->visitedCollections =
|
||||||
$this->scheduledForSynchronization =
|
$this->orphanRemovals = array();
|
||||||
$this->orphanRemovals = [];
|
|
||||||
|
if (null === $entity) {
|
||||||
|
$this->entityChangeSets = $this->scheduledForSynchronization = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_object($entity)) {
|
||||||
|
$entity = [$entity];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($entity as $object) {
|
||||||
|
$oid = spl_object_hash($object);
|
||||||
|
$class = $this->em->getClassMetadata(get_class($object));
|
||||||
|
$this->clearEntityChangeSet($oid);
|
||||||
|
$this->clearScheduledForSynchronization($class, $oid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3099,11 +3122,20 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function clearEntityChangeSet($oid)
|
private function clearEntityChangeSet($oid)
|
||||||
{
|
{
|
||||||
$this->entityChangeSets[$oid] = [];
|
$this->entityChangeSets[$oid] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $class
|
||||||
|
* @param string $oid
|
||||||
|
*/
|
||||||
|
private function clearScheduledForSynchronization($class, $oid)
|
||||||
|
{
|
||||||
|
unset($this->scheduledForSynchronization[$class->rootEntityName][$oid]);
|
||||||
|
}
|
||||||
|
|
||||||
/* PropertyChangedListener implementation */
|
/* PropertyChangedListener implementation */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +163,8 @@ class UnitOfWorkTest extends OrmTestCase
|
|||||||
$this->_unitOfWork->persist($entity);
|
$this->_unitOfWork->persist($entity);
|
||||||
|
|
||||||
$this->_unitOfWork->commit();
|
$this->_unitOfWork->commit();
|
||||||
$this->assertEquals(1, count($persister->getInserts()));
|
$this->assertCount(1, $persister->getInserts());
|
||||||
|
|
||||||
$persister->reset();
|
$persister->reset();
|
||||||
|
|
||||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
||||||
@ -360,6 +361,34 @@ class UnitOfWorkTest extends OrmTestCase
|
|||||||
$this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2));
|
$this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group 5579
|
||||||
|
*/
|
||||||
|
public function testEntityChangeSetNotClearAfterFlushOnEntityOrArrayOfEntity()
|
||||||
|
{
|
||||||
|
// Create and Set first entity
|
||||||
|
$entity1 = new NotifyChangedEntity;
|
||||||
|
$entity1->setData('thedata');
|
||||||
|
$this->_unitOfWork->persist($entity1);
|
||||||
|
|
||||||
|
// Create and Set second entity
|
||||||
|
$entity2 = new NotifyChangedEntity;
|
||||||
|
$entity2->setData('thedata');
|
||||||
|
$this->_unitOfWork->persist($entity2);
|
||||||
|
|
||||||
|
$this->_unitOfWork->commit($entity1);
|
||||||
|
$this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2));
|
||||||
|
|
||||||
|
// Create and Set third entity
|
||||||
|
$entity3 = new NotifyChangedEntity;
|
||||||
|
$entity3->setData('thedata');
|
||||||
|
$this->_unitOfWork->persist($entity3);
|
||||||
|
|
||||||
|
$this->_unitOfWork->commit([$entity1,$entity2]);
|
||||||
|
$this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity3));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data Provider
|
* Data Provider
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user