onFlush Event for persisting all NodeRoutes that needs an update

@param OnFlushEventArgs $args
434518
public function onFlush(OnFlushEventArgs $args)
    {
        $unit = $args->getEntityManager()->getUnitOfWork();
        $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');


        foreach($unit->getScheduledEntityUpdates() as $entity) {

            if(     $entity instanceof RoutableNodeInterface
                &&  $entity->hasAutoNodeRouteGeneration()
            ) {

                $hasNodeRoute = false;
                $routeGenerated = false;

                foreach ($entity->getRoutes() as $route) {
                    if($route instanceof AutoNodeRoute) {
                        $hasNodeRoute = true;
                        break;
                    }
                }

                if(!$hasNodeRoute) {
                    $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
                    $entity->addRoute($routeManager->generateAutoNodeRoute($entity));
                    $routeGenerated = true;
                }


                // check if Node::name has changed
                $changed = $unit->getEntityChangeSet($entity);

                if(     array_key_exists('name', $changed)
                    ||  array_key_exists('parent', $changed)
                    ||  $routeGenerated
                ) {

                    // update all child AutoNodeRoutes
                    $routeManager->getAutoNodeRoutesRecursive($entity);
                    $unit->computeChangeSets();
                }
            }
        }
    }
379455
public function onFlush(OnFlushEventArgs $args)
    {
        $this->em = $args->getEntityManager();
        $this->uow = $this->em->getUnitOfWork();
        $this->widgetRepo = $this->em->getRepository('Victoire\Bundle\WidgetBundle\Entity\Widget');
        $this->viewRepo = $this->em->getRepository('Victoire\Bundle\CoreBundle\Entity\View');

        $updatedEntities = $this->uow->getScheduledEntityUpdates();
        $deletedEntities = $this->uow->getScheduledEntityDeletions();

        //Update View's CSS and inheritors of updated and deleted widgets
        foreach (array_merge($updatedEntities, $deletedEntities) as $entity) {
            if (!($entity instanceof Widget)) {
                continue;
            }

            /* @var Widget $entity */
            $widgetMap = $entity->getWidgetMap();
            if ($widgetMap->getAction() !== WidgetMap::ACTION_DELETE) {
                $view = $widgetMap->getView();
                if ($this->em->contains($view)) {
                    $this->updateViewCss($view);
                    $this->setTemplateInheritorsCssToUpdate($view);
                }
            }
        }

        //Remove CSS of deleted View and update its inheritors
        foreach ($deletedEntities as $entity) {
            if (!($entity instanceof View)) {
                continue;
            }

            $this->viewCssBuilder->removeCssFile($entity->getCssHash());
            $this->setTemplateInheritorsCssToUpdate($entity);
        }

        //Update CSS of updated View and its inheritors
        foreach ($updatedEntities as $entity) {
            if (!($entity instanceof View)) {
                continue;
            }

            $this->updateViewCss($entity);
            $this->setTemplateInheritorsCssToUpdate($entity);
        }

        $this->uow->computeChangeSets();
    }
729492
public function onFlush(OnFlushEventArgs $args)
    {
        $em  = $args->getEntityManager();
        $uow = $em->getUnitOfWork();

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $classMetadata = $em->getClassMetadata(get_class($entity));
            if ($this->isSoftDeletable($classMetadata)) {
                $oldValue = $entity->getDeletedAt();

                $entity->delete();
                $em->persist($entity);

                $uow->propertyChanged($entity, 'deletedAt', $oldValue, $entity->getDeletedAt());
                $uow->scheduleExtraUpdate($entity, [
                    'deletedAt' => [$oldValue, $entity->getDeletedAt()]
                ]);
            }
        }
    }
436785
public function preFlush(PreFlushEventArgs $eventArgs)
    {
        $entityManager = $eventArgs->getEntityManager();
        $unitOfWork = $entityManager->getUnitOfWork();

        foreach ($unitOfWork->getScheduledEntityInsertions() as $object) {
            $this->updateObjectTranslations($entityManager, $object);
        }

        foreach ($unitOfWork->getIdentityMap() as $entities) {
            foreach ($entities as $object) {
                $this->updateObjectTranslations($entityManager, $object);
            }
        }
    }
842467
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $this->em = $eventArgs->getEntityManager();
        $this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
        $this->conn = $this->em->getConnection();
        $this->uow = $this->em->getUnitOfWork();
        $this->platform = $this->conn->getDatabasePlatform();
        $this->revisionId = null; // reset revision

        $processedEntities = [];

        foreach ($this->uow->getScheduledEntityDeletions() as $entity) {
            //doctrine is fine deleting elements multiple times. We are not.
            $hash = $this->getHash($entity);

            if (\in_array($hash, $processedEntities, true)) {
                continue;
            }

            $processedEntities[] = $hash;

            $class = $this->em->getClassMetadata(\get_class($entity));
            if (!$this->metadataFactory->isAudited($class->name)) {
                continue;
            }

            $entityData = array_merge($this->getOriginalEntityData($entity), $this->uow->getEntityIdentifier($entity));
            $this->saveRevisionEntityData($class, $entityData, 'DEL');
        }

        foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
            if (!$this->metadataFactory->isAudited(\get_class($entity))) {
                continue;
            }

            $this->extraUpdates[spl_object_hash($entity)] = $entity;
        }

        foreach ($this->uow->getScheduledEntityUpdates() as $entity) {
            if (!$this->metadataFactory->isAudited(\get_class($entity))) {
                continue;
            }

            $this->extraUpdates[spl_object_hash($entity)] = $entity;
        }
    }
524491
public function preUpdate(LifecycleEventArgs $args)
    {
        $entity = $args->getObject();
        $em = $args->getObjectManager();
        $uow = $em->getUnitOfWork();

        if ($entity instanceof ContentRoute) {
            $template = $this->templates[$entity->getTemplateName()];
            $changeset = $uow->getEntityChangeSet($entity);
            if (isset($changeset['templateName']) && $args->hasChangedField('templateName')) {
                $entity->setTemplate($template['template']);
                $entity->setController($template['controller']);

                $uow->recomputeSingleEntityChangeSet(
                    $em->getClassMetadata('NetworkingInitCmsBundle:ContentRoute'),
                    $entity
                );
            }
        }
    }
400878
public function postFlush(PostFlushEventArgs $eventArgs)
    {        
        foreach ($this->getScheduledForCopyFiles() as $entity){
            $this->fileManager->copyFileToPermanentDirectory($entity);
            $this->fileManager->removeFileFromTemporaryDirectory($entity);
        }
     
        foreach ($this->getScheduledForDeleteFiles() as $entity){
            $this->fileManager->removeAllFiles($entity);
        } 
    }
328945
public function handle($event, $args) {
		if (isset($this->callback[$event])) {
			$this->callback[$event](...$args);
		}
	}
18944
public function postFlush(PostFlushEventArgs $args): void
    {
        if (!empty($this->deleteSharingSubjects) || !empty($this->deleteSharingIdentities)) {
            $this->buildDeleteQuery($args->getEntityManager())->execute();
        }

        $this->deleteSharingSubjects = [];
        $this->deleteSharingIdentities = [];
    }
265690
public function onFlush(OnFlushEventArgs $eventArgs): void
    {
        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();

        foreach ($uow->getScheduledEntityInsertions() as $entity) {
            $this->gatherResourceAndItemTags($entity, false);
            $this->gatherRelationTags($em, $entity);
        }

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            $this->gatherResourceAndItemTags($entity, true);
            $this->gatherRelationTags($em, $entity);
        }

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $this->gatherResourceAndItemTags($entity, true);
            $this->gatherRelationTags($em, $entity);
        }
    }
120367
public function postPersist(LifecycleEventArgs $args)
    {
        $object = $args->getObject();
        if ($object instanceof UploadObjectInterface) {
            $this->storeFileUploads($object);
        }
    }
814767
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $this->entityManager = $eventArgs->getEntityManager();
        $validatedInstancesContainer = new \SplObjectStorage();

        $this->deduplicateValueObjectInsertions();

        $unitOfWork = $this->entityManager->getUnitOfWork();
        foreach ($unitOfWork->getScheduledEntityInsertions() as $entity) {
            $this->validateObject($entity, $validatedInstancesContainer);
        }

        foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
            $this->validateObject($entity, $validatedInstancesContainer);
        }
    }
33585
public static function flushEvents(): void
    {
        $client = Hub::getCurrent()->getClient();

        if ($client instanceof Client) {
            $transportProperty = new \ReflectionProperty(Client::class, 'transport');
            $transportProperty->setAccessible(true);

            $transport = $transportProperty->getValue($client);

            if ($transport instanceof HttpTransport) {
                $closure = \Closure::bind(function () {
                    $this->cleanupPendingRequests();
                }, $transport, $transport);

                $closure();
            }
        }
    }
26950
public function postUpdate(LifecycleEventArgs $args): void
    {
        // Get the object and make sure it is what we need.
        $object = $args->getObject();
        if (!$object instanceof PublishableInterface) {
            return;
        }

        // Get the changeset from the unit of work.
        $uow = $args->getObjectManager()->getUnitOfWork();
        $changeset = $uow->getEntityChangeset($object);

        // If the published state changed fire the published event.
        if (isset($changeset['published'])
            && false === $changeset['published'][0]
            && true === $changeset['published'][1]) {
            $event = new EntityPublishedEvent($object);
            $this->event_dispatcher->dispatch(EntityPublishedEvent::NAME, $event);
        }
    }
176838
public function postUpdate(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof BlockInterface) {
            $this->getService($args)->postUpdate($args->getObject());
        }
    }
374962
public function onFlush($args)
    {
        if (!$this->isDirty) {
            /** @var $em \Doctrine\ORM\EntityManager */
            $em = $args->getEntityManager();

            /** @var $uow \Doctrine\ORM\UnitOfWork */
            $uow = $em->getUnitOfWork();

            $array = array(
                $uow->getScheduledEntityUpdates(),
                $uow->getScheduledEntityDeletions(),
                $uow->getScheduledEntityInsertions(),
                $uow->getScheduledCollectionUpdates(),
                $uow->getScheduledCollectionDeletions(),
                $uow->getScheduledCollectionDeletions(),
                $uow->getScheduledCollectionUpdates()
            );

            foreach ($array as $obj) {
                foreach ($obj as $element) {
                    if ($element instanceof Entity\Message
                     || $element instanceof Entity\MessageTranslation
                    ) {
                        $this->isDirty = true;
                        break 2;
                    }
                }
            }
        }

        $this->flushCache();
    }
337923
public function beforeUpdate(array &$args) {
        $data = &$args[1];
        foreach ($this->_fields as $field) {
            if (!empty($data[$field])) {
                $data[$field] = $this->filter($data[$field], $this->getConfig());
            }
        }
    }