I have setup a doctrine EntityListener. I need to execute some code in the postRemove
event which must be out of any doctrine transaction. However:
public function postRemove(Image $image, LifecycleEventArgs $event)
{
$isActive = $event->getEntityManager()->getConnection()->isTransactionActive();
dump($isActive);
}
always dumps true.
No matter if I commit or flush inside the postRemove() method; I tried starting transaction in preRemove() and committing it in postRemove(), but that doesn't help.
Question: Is there a way to prevent Doctrine from wrapping postRemove() into transaction? If no, what is the best way for me to execute code which would be out of transaction? I don't care if it happens immediately or on kernel terminate, as long as it eventually happens.
I have an idea to create a destructor method in the EntityListener, and run the code when Listener destructs, but I don't know how reliable that would be. Maybe there are other (better) options?
thanks!