DDC-1278 - EntityManager::clear($entity) support
added new parameter $entityName for UnitOfWork::clear() removed not implemented exception in EntityManager:clear()
This commit is contained in:
parent
e13720c33d
commit
05fb0b913a
@ -421,16 +421,11 @@ class EntityManager implements ObjectManager
|
||||
* Clears the EntityManager. All entities that are currently managed
|
||||
* by this EntityManager become detached.
|
||||
*
|
||||
* @param string $entityName
|
||||
* @param string $entityName if given, only entities of this type will get detached
|
||||
*/
|
||||
public function clear($entityName = null)
|
||||
{
|
||||
if ($entityName === null) {
|
||||
$this->unitOfWork->clear();
|
||||
} else {
|
||||
//TODO
|
||||
throw new ORMException("EntityManager#clear(\$entityName) not yet implemented.");
|
||||
}
|
||||
$this->unitOfWork->clear($entityName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1790,28 +1790,41 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
/**
|
||||
* Clears the UnitOfWork.
|
||||
*
|
||||
* @param strin $entityName if given, only entities of this type will get detached
|
||||
*/
|
||||
public function clear()
|
||||
public function clear($entityName = null)
|
||||
{
|
||||
$this->identityMap =
|
||||
$this->entityIdentifiers =
|
||||
$this->originalEntityData =
|
||||
$this->entityChangeSets =
|
||||
$this->entityStates =
|
||||
$this->scheduledForDirtyCheck =
|
||||
$this->entityInsertions =
|
||||
$this->entityUpdates =
|
||||
$this->entityDeletions =
|
||||
$this->collectionDeletions =
|
||||
$this->collectionUpdates =
|
||||
$this->extraUpdates =
|
||||
$this->orphanRemovals = array();
|
||||
if ($this->commitOrderCalculator !== null) {
|
||||
$this->commitOrderCalculator->clear();
|
||||
}
|
||||
if ($entityName === null) {
|
||||
$this->identityMap =
|
||||
$this->entityIdentifiers =
|
||||
$this->originalEntityData =
|
||||
$this->entityChangeSets =
|
||||
$this->entityStates =
|
||||
$this->scheduledForDirtyCheck =
|
||||
$this->entityInsertions =
|
||||
$this->entityUpdates =
|
||||
$this->entityDeletions =
|
||||
$this->collectionDeletions =
|
||||
$this->collectionUpdates =
|
||||
$this->extraUpdates =
|
||||
$this->orphanRemovals = array();
|
||||
if ($this->commitOrderCalculator !== null) {
|
||||
$this->commitOrderCalculator->clear();
|
||||
}
|
||||
|
||||
if ($this->evm->hasListeners(Events::onClear)) {
|
||||
$this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user