Clean post flush event added. Triggered after post flush after all clears. Event is flush-safe
This commit is contained in:
parent
b3805549d9
commit
6f5b001a6b
34
lib/Doctrine/ORM/Event/CleanPostFlushEventArgs.php
Normal file
34
lib/Doctrine/ORM/Event/CleanPostFlushEventArgs.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
@ -35,6 +35,7 @@ use Doctrine\Common\Persistence\ObjectManagerAware;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Proxy\Proxy;
|
||||
|
||||
use Doctrine\ORM\Event\CleanPostFlushEventArgs;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use Doctrine\ORM\Event\PreFlushEventArgs;
|
||||
@ -354,6 +355,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$this->orphanRemovals)) {
|
||||
$this->dispatchOnFlushEvent();
|
||||
$this->dispatchPostFlushEvent();
|
||||
$this->dispatchCleanPostFlushEvent();
|
||||
|
||||
return; // Nothing to do.
|
||||
}
|
||||
@ -437,6 +439,8 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$this->visitedCollections =
|
||||
$this->scheduledForSynchronization =
|
||||
$this->orphanRemovals = array();
|
||||
|
||||
$this->dispatchCleanPostFlushEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3326,6 +3330,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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user