Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deduplication of internal UnitOfWork methods #1574

Merged
merged 4 commits into from
Dec 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -3259,41 +3259,35 @@ public function isReadOnly($object)
*/
private function afterTransactionComplete()
{
if ( ! $this->hasCache) {
return;
}

foreach ($this->persisters as $persister) {
if ($persister instanceof CachedPersister) {
$persister->afterTransactionComplete();
}
}

foreach ($this->collectionPersisters as $persister) {
if ($persister instanceof CachedPersister) {
$persister->afterTransactionComplete();
}
}
$this->performCallbackOnCachedPersister(function (CachedPersister $persister) {
$persister->afterTransactionComplete();
});
}

/**
* Perform whatever processing is encapsulated here after completion of the rolled-back.
*/
private function afterTransactionRolledBack()
{
$this->performCallbackOnCachedPersister(function (CachedPersister $persister) {
$persister->afterTransactionRolledBack();
});
}

/**
* Performs an action after the transaction.
*
* @param callable $callback
*/
private function performCallbackOnCachedPersister(callable $callback)
{
if ( ! $this->hasCache) {
return;
}

foreach ($this->persisters as $persister) {
if ($persister instanceof CachedPersister) {
$persister->afterTransactionRolledBack();
}
}

foreach ($this->collectionPersisters as $persister) {
foreach (array_merge($this->persisters, $this->collectionPersisters) as $persister) {
if ($persister instanceof CachedPersister) {
$persister->afterTransactionRolledBack();
$callback($persister);
}
}
}
Expand Down