Gets all the entities to flush.

@param OnFlushEventArgs $eventArgs Event args
774297
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        //reduce the amount of flushes to increase performances !
        //you can also activate the log from the claroline.persistence.object_manager service when you use it
        //if you want additional informations about transactions
        if ($this->activateLog) {
            $this->log('onFlush event fired !!!', LogLevel::DEBUG);

            if (self::DEBUG_NONE !== $this->debugLevel) {
                $stack = debug_backtrace();

                foreach ($stack as $call) {
                    if (isset($call['file'])) {
                        $file = $call['file'];
                        if (self::DEBUG_CLAROLINE === $this->debugLevel) {
                            if (strpos($file, 'claroline')) {
                                $this->logTrace($call);
                            }
                        } elseif (self::DEBUG_ALL === $this->debugLevel) {
                            $this->logTrace($call);
                        } elseif (self::DEBUG_VENDOR === $this->debugLevel) {
                            if (strpos($file, $this->debugVendor)) {
                                $this->logTrace($call);
                            }
                        }
                    }
                }

                $this->log('Data printed !');
            }
        }
    }
1221897
public function flushEvents(): StreamEvents {
        $events = $this->streamEvents->copy();

        $this->streamEvents = StreamEvents::make();

        return $events;
    }
1120054
public function postLoad(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::postLoad, $eventArgs->getEntity(), $eventArgs);
        }
    }
719399
public function prePersist(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::prePersist, $eventArgs->getEntity(), $eventArgs);
        }
    }
415772
public function preFlush(PreFlushEventArgs $args)
    {
        $entityManager = $args->getEntityManager();
        $scheduledInsertions = $entityManager
            ->getUnitOfWork()
            ->getScheduledEntityInsertions();

        $this
            ->categoryIntegrityFixer
            ->fixCategoriesIntegrityByArray($scheduledInsertions);
    }
52160
public static function onFlushContent(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            return;
        }

        $application = $event->getApplication();
        $em = $application->getEntityManager();
        $uow = $em->getUnitOfWork();
        if ($uow->isScheduledForDelete($content)) {
            return;
        }

        if (null !== $page = $content->getMainNode()) {
            if (null !== $page->getMetaData()) {
                $newEvent = new Event($page, $content);
                $newEvent->setDispatcher($event->getDispatcher());
                self::onFlushPage($newEvent);
            }
        }
    }
994625
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $dm  = $eventArgs->getDocumentManager();
        $uow = $dm->getUnitOfWork();
        
        $filter = function ($element) {
            return $element instanceof ApplicationInterface
                   && $element->getPermissions()->hasChanged();
        };
        
        $inserts = array_filter($uow->getScheduledDocumentInsertions(), $filter);
        $updates = array_filter($uow->getScheduledDocumentUpdates(), $filter);
        
        foreach (array($inserts, $updates) as $isUpdate => $documents) {
            foreach ($documents as $document) { /* @var \Applications\Entity\Application $document */
                $permissions = $document->getPermissions();
               
                foreach ($document->getAttachments() as $attachment) {  /* @var \Applications\Entity\Attachment $attachment */
                    $attachment->getPermissions()
                               ->clear()
                               ->inherit($permissions);
                    if ($isUpdate) {
                        $uow->computeChangeSet(
                            $dm->getClassMetadata(get_class($attachment)),
                            $attachment
                        );
                    }
                }
                
                if ($image = $document->getContact()->getImage()) {
                    $image->getPermissions()
                          ->clear()
                          ->inherit($permissions);
                    if ($isUpdate) {
                        $uow->computeChangeSet(
                            $dm->getClassMetadata(get_class($image)),
                            $image
                        );
                    }
                }
            }
        }
    }
817252
public function postRemoveEntity(LifecycleEventArgs $eventArgs)
    {
        $file = $eventArgs->getDocument();
        if (!$file instanceof Attachment) {
            return;
        }
        
        $fileId = new \MongoId($file->getId());
        $dm = $eventArgs->getDocumentManager();
        $dm->createQueryBuilder('Cv\Entity\Cv')
           ->update()->multiple(true)
           ->field('attachments')->equals($fileId)->pull($fileId)
           ->getQuery()->execute();
    }
885969
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        /** @var ClassMetadata $metadata */
        $metadata = $eventArgs->getClassMetadata();

        $reflectionClass = $metadata->getReflectionClass();

        if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Sortable')) {
            return;
        } // return if current entity doesn't use Sortable trait

        $this->logger->debug('[SortableListener] Entering SortableListener for « loadClassMetadata » event');

        // setting default mapping configuration for Sortable
        // sortRank
        $metadata->mapField([
            'fieldName' => 'sortRank',
            'type'      => 'float',
            'nullable'  => false,
            'default'   => 65536,
        ]);

        // add index on sort_rank column
        if (!isset($metadata->table['indexes'])) {
            $metadata->table['indexes'] = [];
        }
        $metadata->table['indexes']['sort_rank'] = ['columns' => ['sort_rank']];

        $this->logger->debug(
            '[SortableListener] Added Sortable mapping metadata to Entity', ['class' => $metadata->getName()]
        );
    }
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;
        }
    }
985486
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $metadata = $eventArgs->getClassMetadata();

        if ($metadata->getName() === self::ROOT_CHARACTERISTICS_CLASS) {
            $metadata->setDiscriminatorMap($this->characteristicsClassesMap);
        }
    }
1252264
public function onFlush(OnFlushEventArgs $args): void
    {
        $uow = $args->getEntityManager()->getUnitOfWork();
        $collection = $this->getAllCollections($uow);
        $invalidates = [];

        // check all scheduled insertions
        foreach ($collection as $object) {
            $invalidate = $this->invalidateCache($uow, $object);

            if (\is_string($invalidate)) {
                $invalidates[] = $invalidate;
            }
        }

        $this->flushCache(array_unique($invalidates));
    }
433466
protected function _triggerEvent($eventName, $entity, $eventArgs)
    {
        if (null === $this->_application) {
            return;
        }

        $dispatcher = $this->_application->getEventDispatcher();
        if (null !== $dispatcher) {
            $dispatcher->triggerEvent($eventName, $entity, $eventArgs);
        }
    }
99058
public function prePersist(EventArgs $args)
    {
        $em = $args->getEntityManager();
        $object = $args->getObject();
        $class = get_class($object);
        $meta = $em->getClassMetadata($class);

        $reflectionClass = $meta->getReflectionClass();

        if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Sortable')) {
            return;
        } // return if current entity doesn't use Sortable trait

        if ($object->getSortRank()) {
            return;
        }

        $maxPos = $this->getMaxPosition($em, $meta);
        $maxPos = $maxPos ? $maxPos + 1000 : 65536;

        $object->setSortRank($maxPos);
        $this->maxPositions[$class] = $maxPos;
    }
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();
    }
935447
public function onFlush(EventArgs $args)
    {
        $ea = $this->getEventAdapter($args);
        $om = $ea->getObjectManager();
        $uow = $om->getUnitOfWork();
        // check all scheduled updates
        $all = array_merge($ea->getScheduledObjectInsertions($uow), $ea->getScheduledObjectUpdates($uow));
        foreach ($all as $object) {
            $meta = $om->getClassMetadata(get_class($object));
            if (!$config = $this->getConfiguration($om, $meta->name)) {
                continue;
            }
            $changeSet = $ea->getObjectChangeSet($uow, $object);
            $needChanges = false;

            if ($uow->isScheduledForInsert($object) && isset($config['create'])) {
                foreach ($config['create'] as $field) {
                    list(, $new) = $changeSet[$field];
                    if ($new === null) { // let manual values
                        $needChanges = true;
                        $this->updateField($object, $ea, $meta, $field);
                    }
                }
            }

            if (isset($config['update'])) {
                foreach ($config['update'] as $field) {
                    $isInsertAndNull = $uow->isScheduledForInsert($object) && $changeSet[$field][1] === null;
                    if (!isset($changeSet[$field]) || $isInsertAndNull) { // let manual values
                        $needChanges = true;
                        $this->updateField($object, $ea, $meta, $field);
                    }
                }
            }

            if (!$uow->isScheduledForInsert($object) && isset($config['change'])) {
                foreach ($config['change'] as $options) {
                    if (isset($changeSet[$options['field']])) {
                        continue; // value was set manually
                    }

                    if (!is_array($options['trackedField'])) {
                        $singleField = true;
                        $trackedFields = array($options['trackedField']);
                    } else {
                        $singleField = false;
                        $trackedFields = $options['trackedField'];
                    }

                    foreach ($trackedFields as $tracked) {
                        $trackedChild = null;
                        $parts = explode('.', $tracked);
                        if (isset($parts[1])) {
                            if (isset($changeSet[$tracked])) {
                                $changes = $changeSet[$tracked];
                                if ($changes[0] != $changes[1]) {
                                    $needChanges = true;
                                    $this->updateField($object, $ea, $meta, $options['field']);
                                    continue;
                                }
                            }

                            $tracked = $parts[0];
                            $trackedChild = $parts[1];
                        }

                        if (isset($changeSet[$tracked])) {
                            $changes = $changeSet[$tracked];
                            if (isset($trackedChild)) {
                                $changingObject = $changes[1];
                                if (!is_object($changingObject)) {
                                    throw new UnexpectedValueException(
                                        "Field - [{$field}] is expected to be object in class - {$meta->name}"
                                    );
                                }
                                $objectMeta = $om->getClassMetadata(get_class($changingObject));
                                $om->initializeObject($changingObject);
                                $value = $objectMeta->getReflectionProperty($trackedChild)->getValue($changingObject);
                            } else {
                                $value = $changes[1];
                            }

                            if (($singleField && in_array($value, (array) $options['value'])) || $options['value'] === null) {
                                $needChanges = true;
                                $this->updateField($object, $ea, $meta, $options['field']);
                            }
                        }
                    }
                }
            }

            if ($needChanges) {
                $ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
            }
        }
    }
418727
public function loadClassMetadata(EventArgs $eventArgs)
    {
        if ( ! $eventArgs instanceof CommonEventArgs
            && ! $eventArgs instanceof OrmEventArgs
        ) {
            throw InvalidArgumentException::create(
                'Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs',
                $eventArgs
            );
        }
        $ea = $this->getEventAdapter($eventArgs);
        $this->loadMetadataForObjectClass($ea->getObjectManager(), $eventArgs->getClassMetadata());
    }