Ensure onFlush and postFlush events are always raised
This commit is contained in:
parent
ce290bc99b
commit
9322ca7052
@ -281,16 +281,15 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! ($this->entityInsertions ||
|
$anythingToDo =
|
||||||
$this->entityDeletions ||
|
$this->entityInsertions ||
|
||||||
$this->entityUpdates ||
|
$this->entityDeletions ||
|
||||||
$this->collectionUpdates ||
|
$this->entityUpdates ||
|
||||||
$this->collectionDeletions ||
|
$this->collectionUpdates ||
|
||||||
$this->orphanRemovals)) {
|
$this->collectionDeletions ||
|
||||||
return; // Nothing to do.
|
$this->orphanRemovals;
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->orphanRemovals) {
|
if ($anythingToDo && $this->orphanRemovals) {
|
||||||
foreach ($this->orphanRemovals as $orphan) {
|
foreach ($this->orphanRemovals as $orphan) {
|
||||||
$this->remove($orphan);
|
$this->remove($orphan);
|
||||||
}
|
}
|
||||||
@ -301,57 +300,59 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
$this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->em));
|
$this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->em));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we need a commit order to maintain referential integrity
|
if ($anythingToDo) {
|
||||||
$commitOrder = $this->getCommitOrder();
|
// Now we need a commit order to maintain referential integrity
|
||||||
|
$commitOrder = $this->getCommitOrder();
|
||||||
|
|
||||||
$conn = $this->em->getConnection();
|
$conn = $this->em->getConnection();
|
||||||
$conn->beginTransaction();
|
$conn->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->entityInsertions) {
|
if ($this->entityInsertions) {
|
||||||
foreach ($commitOrder as $class) {
|
foreach ($commitOrder as $class) {
|
||||||
$this->executeInserts($class);
|
$this->executeInserts($class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->entityUpdates) {
|
if ($this->entityUpdates) {
|
||||||
foreach ($commitOrder as $class) {
|
foreach ($commitOrder as $class) {
|
||||||
$this->executeUpdates($class);
|
$this->executeUpdates($class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Extra updates that were requested by persisters.
|
// Extra updates that were requested by persisters.
|
||||||
if ($this->extraUpdates) {
|
if ($this->extraUpdates) {
|
||||||
$this->executeExtraUpdates();
|
$this->executeExtraUpdates();
|
||||||
}
|
|
||||||
|
|
||||||
// Collection deletions (deletions of complete collections)
|
|
||||||
foreach ($this->collectionDeletions as $collectionToDelete) {
|
|
||||||
$this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete);
|
|
||||||
}
|
|
||||||
// Collection updates (deleteRows, updateRows, insertRows)
|
|
||||||
foreach ($this->collectionUpdates as $collectionToUpdate) {
|
|
||||||
$this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entity deletions come last and need to be in reverse commit order
|
|
||||||
if ($this->entityDeletions) {
|
|
||||||
for ($count = count($commitOrder), $i = $count - 1; $i >= 0; --$i) {
|
|
||||||
$this->executeDeletions($commitOrder[$i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collection deletions (deletions of complete collections)
|
||||||
|
foreach ($this->collectionDeletions as $collectionToDelete) {
|
||||||
|
$this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete);
|
||||||
|
}
|
||||||
|
// Collection updates (deleteRows, updateRows, insertRows)
|
||||||
|
foreach ($this->collectionUpdates as $collectionToUpdate) {
|
||||||
|
$this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Entity deletions come last and need to be in reverse commit order
|
||||||
|
if ($this->entityDeletions) {
|
||||||
|
for ($count = count($commitOrder), $i = $count - 1; $i >= 0; --$i) {
|
||||||
|
$this->executeDeletions($commitOrder[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn->commit();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->em->close();
|
||||||
|
$conn->rollback();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn->commit();
|
// Take new snapshots from visited collections
|
||||||
} catch (Exception $e) {
|
foreach ($this->visitedCollections as $coll) {
|
||||||
$this->em->close();
|
$coll->takeSnapshot();
|
||||||
$conn->rollback();
|
}
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take new snapshots from visited collections
|
|
||||||
foreach ($this->visitedCollections as $coll) {
|
|
||||||
$coll->takeSnapshot();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raise postFlush
|
// Raise postFlush
|
||||||
|
Loading…
x
Reference in New Issue
Block a user