1
0
mirror of synced 2024-12-05 03:06:05 +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 b3805549d9
commit 6f5b001a6b
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

@ -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
*