public function postFlush(PostFlushEventArgs $eventArgs)
    {
        $em = $eventArgs->getEntityManager();
        foreach ($this->flushedBusinessEntities as $entity) {
            $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);
            //find all BT that can represent the businessEntity
            $businessTemplates = $em->getRepository('VictoireBusinessPageBundle:BusinessTemplate')->findPagePatternByBusinessEntity($businessEntity);
            foreach ($businessTemplates as $businessTemplate) {
                // Generate a viewReference for each BT translation
                foreach ($businessTemplate->getTranslations() as $translation) {
                    $businessTemplate->setCurrentLocale($translation->getLocale());

                    if ($page = $em->getRepository(
                        'Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage'
                    )->findPageByBusinessEntityAndPattern($businessTemplate, $entity, $businessEntity)
                    ) {
                        //if it's a BP we update the BP
                        $this->businessPageBuilder->updatePageParametersByEntity($page, $entity);
                    } else {
                        $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
                            $businessTemplate,
                            $entity,
                            $em
                        );
                    }
                    if ($this->businessPageHelper->isEntityAllowed($businessTemplate, $entity, $em)) {
                        //update the reference
                        $event = new ViewReferenceEvent($page);
                        $this->dispatcher->dispatch(ViewReferenceEvents::UPDATE_VIEW_REFERENCE, $event);
                    }
                }
            }
        }

        foreach ($this->flushedBusinessTemplates as $entity) {
            $businessEntityId = $entity->getBusinessEntityId();
            $businessEntity = $this->businessEntityHelper->findById($businessEntityId);
            //find all entities
            $entities = $this->businessPageHelper->getEntitiesAllowed($entity, $em);
            // Generate a viewReference for each BT translation
            foreach ($entity->getTranslations() as $translation) {
                $entity->setCurrentLocale($translation->getLocale());
                foreach ($entities as $be) {
                    if ($this->businessPageHelper->isEntityAllowed($entity, $be, $em)) {
                        if ($page = $em->getRepository(
                            'Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage'
                        )->findPageByBusinessEntityAndPattern($entity, $be, $businessEntity)
                        ) {
                            //rebuild page if its a BP
                            $this->businessPageBuilder->updatePageParametersByEntity($page, $be);
                        } else {
                            $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
                                $entity,
                                $be,
                                $em
                            );
                        }
                        // update reference
                        $event = new ViewReferenceEvent($page);
                        $this->dispatcher->dispatch(ViewReferenceEvents::UPDATE_VIEW_REFERENCE, $event);
                    }
                }
            }
        }
        $this->flushedBusinessEntities->clear();
        $this->flushedBusinessTemplates->clear();
    }