PartKeepr\CategoryBundle\EventListener\RootCategoryListener::onFlush PHP Method

onFlush() public method

Checks that only one root category exists.
public onFlush ( Doctrine\ORM\Event\OnFlushEventArgs $eventArgs )
$eventArgs Doctrine\ORM\Event\OnFlushEventArgs The event arguments as given by Doctrine
    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);
            }
        }
    }