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:
parent
3c3b7364ba
commit
c337f8f5c7
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user