DDC-1278 - EntityManager::clear($entity) support
cascade detach operation only on entity name entities
This commit is contained in:
parent
745535d269
commit
25f5ff0ca1
@ -1515,8 +1515,9 @@ class UnitOfWork implements PropertyChangedListener
|
||||
*
|
||||
* @param object $entity
|
||||
* @param array $visited
|
||||
* @param string $entityName detach only entities of this type when given
|
||||
*/
|
||||
private function doDetach($entity, array &$visited)
|
||||
private function doDetach($entity, array &$visited, $entityName = null)
|
||||
{
|
||||
$oid = spl_object_hash($entity);
|
||||
if (isset($visited[$oid])) {
|
||||
@ -1539,7 +1540,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
return;
|
||||
}
|
||||
|
||||
$this->cascadeDetach($entity, $visited);
|
||||
$this->cascadeDetach($entity, $visited, $entityName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1617,8 +1618,9 @@ class UnitOfWork implements PropertyChangedListener
|
||||
*
|
||||
* @param object $entity
|
||||
* @param array $visited
|
||||
* @param string $entityName detach only entities of this type when given
|
||||
*/
|
||||
private function cascadeDetach($entity, array &$visited)
|
||||
private function cascadeDetach($entity, array &$visited, $entityName = null)
|
||||
{
|
||||
$class = $this->em->getClassMetadata(get_class($entity));
|
||||
foreach ($class->associationMappings as $assoc) {
|
||||
@ -1632,10 +1634,14 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$relatedEntities = $relatedEntities->unwrap();
|
||||
}
|
||||
foreach ($relatedEntities as $relatedEntity) {
|
||||
$this->doDetach($relatedEntity, $visited);
|
||||
if ($entityName === null || get_class($relatedEntity) == $entityName) {
|
||||
$this->doDetach($relatedEntity, $visited, $entityName);
|
||||
}
|
||||
}
|
||||
} else if ($relatedEntities !== null) {
|
||||
$this->doDetach($relatedEntities, $visited);
|
||||
if ($entityName === null || get_class($relatedEntities) == $entityName) {
|
||||
$this->doDetach($relatedEntities, $visited, $entityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1812,20 +1818,20 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ($this->commitOrderCalculator !== null) {
|
||||
$this->commitOrderCalculator->clear();
|
||||
}
|
||||
|
||||
if ($this->evm->hasListeners(Events::onClear)) {
|
||||
$this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em));
|
||||
}
|
||||
} else {
|
||||
$visited = array();
|
||||
foreach ($this->identityMap as $className => $entities) {
|
||||
if ($className === $entityName) {
|
||||
foreach ($entities as $entity) {
|
||||
$this->doDetach($entity, $visited);
|
||||
$this->doDetach($entity, $visited, $entityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->evm->hasListeners(Events::onClear)) {
|
||||
$this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user