Merge branch 'fix/#5850-clearing-specific-entity-name-should-clear-also-its-entity-insertions-2.5' into 2.5
Close #5850 Close #5849
This commit is contained in:
commit
0af9ee0140
@ -2407,17 +2407,8 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$this->commitOrderCalculator->clear();
|
||||
}
|
||||
} else {
|
||||
$visited = array();
|
||||
|
||||
foreach ($this->identityMap as $className => $entities) {
|
||||
if ($className !== $entityName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$this->doDetach($entity, $visited, false);
|
||||
}
|
||||
}
|
||||
$this->clearIdentityMapForEntityName($entityName);
|
||||
$this->clearEntityInsertionsForEntityName($entityName);
|
||||
}
|
||||
|
||||
if ($this->evm->hasListeners(Events::onClear)) {
|
||||
@ -3471,4 +3462,32 @@ class UnitOfWork implements PropertyChangedListener
|
||||
{
|
||||
$this->hydrationCompleteHandler->hydrationComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entityName
|
||||
*/
|
||||
private function clearIdentityMapForEntityName($entityName)
|
||||
{
|
||||
if (! isset($this->identityMap[$entityName])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$visited = [];
|
||||
|
||||
foreach ($this->identityMap[$entityName] as $entity) {
|
||||
$this->doDetach($entity, $visited, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entityName
|
||||
*/
|
||||
private function clearEntityInsertionsForEntityName($entityName)
|
||||
{
|
||||
foreach ($this->entityInsertions as $hash => $entity) {
|
||||
if (get_class($entity) === $entityName) {
|
||||
unset($this->entityInsertions[$hash]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ use Doctrine\Tests\Mocks\EntityPersisterMock;
|
||||
use Doctrine\Tests\Mocks\UnitOfWorkMock;
|
||||
use Doctrine\Tests\Models\Forum\ForumAvatar;
|
||||
use Doctrine\Tests\Models\Forum\ForumUser;
|
||||
use Doctrine\Tests\Models\GeoNames\City;
|
||||
use Doctrine\Tests\Models\GeoNames\Country;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@ -321,6 +324,28 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 5849
|
||||
* @group 5850
|
||||
*/
|
||||
public function testPersistedEntityAndClearManager()
|
||||
{
|
||||
$entity1 = new City(123, 'London');
|
||||
$entity2 = new Country(456, 'United Kingdom');
|
||||
|
||||
$this->_unitOfWork->persist($entity1);
|
||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity1));
|
||||
|
||||
$this->_unitOfWork->persist($entity2);
|
||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity2));
|
||||
|
||||
$this->_unitOfWork->clear(Country::class);
|
||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity1));
|
||||
$this->assertFalse($this->_unitOfWork->isInIdentityMap($entity2));
|
||||
$this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity1));
|
||||
$this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data Provider
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user