1
0
mirror of synced 2025-02-09 08:49:26 +03:00

DDC-4022 deduplication of internal UnitOfWork methods

the methods UnitOfWork#afterTransactionRolledBack() and UnitOfWork#afterTransactionComplete do almost the same, so it can be abstracted into another private method.
This commit is contained in:
Maximilian Bosch 2015-11-30 16:22:11 +01:00 committed by Ma27
parent 3c3b7364ba
commit c337f8f5c7

View File

@ -3259,21 +3259,9 @@ class UnitOfWork implements PropertyChangedListener
*/
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->doAfterTransaction(function (CachedPersister $persister) {
$persister->afterTransactionComplete();
});
}
/**
@ -3281,19 +3269,23 @@ class UnitOfWork implements PropertyChangedListener
*/
private function afterTransactionRolledBack()
{
if ( ! $this->hasCache) {
$this->doAfterTransaction(function (CachedPersister $persister) {
$persister->afterTransactionRolledBack();
});
}
/**
* Performs an action after the transaction.
*/
private function doAfterTransaction(callable $callback)
{
if (!$this->hasCache) {
return;
}
foreach ($this->persisters as $persister) {
foreach (array_merge($this->persisters, $this->collectionPersisters) as $persister) {
if ($persister instanceof CachedPersister) {
$persister->afterTransactionRolledBack();
}
}
foreach ($this->collectionPersisters as $persister) {
if ($persister instanceof CachedPersister) {
$persister->afterTransactionRolledBack();
call_user_func($callback, $persister);
}
}
}