public function onFlush(OnFlushEventArgs $eventArgs)
{
$entityManager = $eventArgs->getEntityManager();
$uow = $entityManager->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $insertion) {
if (is_a($insertion, $this->container->get($this->service)->getEntityClass())) {
$this->checkForRoot($insertion);
}
}
foreach ($uow->getScheduledEntityUpdates() as $updated) {
if (is_a($updated, $this->container->get($this->service)->getEntityClass())) {
$this->checkForRoot($updated);
}
}
foreach ($uow->getScheduledEntityDeletions() as $deletion) {
if (is_a($deletion, $this->container->get($this->service)->getEntityClass())) {
$this->ensureRootStays($deletion);
}
}
}