1
0
mirror of synced 2024-12-04 18:56:06 +03:00

Clean post flush event added. Triggered after post flush after all clears. Event is flush-safe

This commit is contained in:
1on 2018-03-28 12:36:55 +03:00 committed by Sergey Linnik
parent 57d2bf1f26
commit 62f6ee3303
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace Doctrine\ORM\Event;
use Doctrine\Common\EventArgs;
use Doctrine\ORM\EntityManagerInterface;
/**
* Event triggers in the end of flush after all actions and clears in uow
* Flush can be called inside listeners of this event
*/
class CleanPostFlushEventArgs extends EventArgs
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @return EntityManagerInterface
*/
public function getEntityManager(): EntityManagerInterface
{
return $this->em;
}
}

View File

@ -157,6 +157,16 @@ final class Events
*/
const postFlush = 'postFlush';
/**
* The cleanPostFlush event occurs when the EntityManager#flush() operation is invoked and
* after all actual database operations are executed successfully.
* All information about performed database operations has been cleared before raising cleanPostFlush event.
* This means that flush calls can be performed in cleanPostFlush event.
*
* @var string
*/
const cleanPostFlush = 'cleanPostFlush';
/**
* The onClear event occurs when the EntityManager#clear() operation is invoked,
* after all references to entities have been removed from the unit of work.

View File

@ -27,6 +27,7 @@ use Doctrine\Common\Persistence\ObjectManagerAware;
use Doctrine\Common\PropertyChangedListener;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Cache\Persister\CachedPersister;
use Doctrine\ORM\Event\CleanPostFlushEventArgs;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\ListenersInvoker;
use Doctrine\ORM\Event\OnFlushEventArgs;
@ -355,6 +356,7 @@ class UnitOfWork implements PropertyChangedListener
$this->orphanRemovals)) {
$this->dispatchOnFlushEvent();
$this->dispatchPostFlushEvent();
$this->dispatchCleanPostFlushEvent();
return; // Nothing to do.
}
@ -430,6 +432,8 @@ class UnitOfWork implements PropertyChangedListener
$this->dispatchPostFlushEvent();
$this->postCommitCleanup($entity);
$this->dispatchCleanPostFlushEvent();
}
/**
@ -3396,6 +3400,13 @@ class UnitOfWork implements PropertyChangedListener
}
}
private function dispatchCleanPostFlushEvent()
{
if ($this->evm->hasListeners(Events::cleanPostFlush)) {
$this->evm->dispatchEvent(Events::cleanPostFlush, new CleanPostFlushEventArgs($this->em));
}
}
/**
* Verifies if two given entities actually are the same based on identifier comparison
*