Logs the entity changes

@param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs
514846
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();

        foreach ($uow->getScheduledEntityInsertions() as $entity) {
            $this->debug('Inserting entity '.get_class($entity).'. Fields: '.
                             json_encode($uow->getEntityChangeSet($entity)));
        }

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            $add = '';
            if (method_exists($entity, '__toString')) {
                $add = ' '.$entity->__toString();
            } elseif (method_exists($entity, 'getId')) {
                $add = ' with id '.$entity->getId();
            }

            $this->debug('Updating entity '.get_class($entity).$add.'. Data: '.
                             json_encode($uow->getEntityChangeSet($entity)));
        }

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $add = '';
            if (method_exists($entity, '__toString')) {
                $add = ' '.$entity->__toString();
            } elseif (method_exists($entity, 'getId')) {
                $add = ' with id '.$entity->getId();
            }

            $this->debug('Deleting entity '.get_class($entity).$add.'.');
        }
    }
653064
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        /**
         * @var ClassMetadata
         */
        $metadata = $eventArgs->getClassMetadata();
        $className = $metadata->getName();

        if (!key_exists($className, $this->extendedClasses)) {
            return;
        }

        $this->logger->debug('[OuterExtensionListener] Entering listener for « loadClassMetadata » event', ['class' => $className]);

        foreach ($this->extendedClasses[$className] as $locator) {
            $outMetadata = new ClassMetadata($className);
            // TODO: use different drivers (configuration)
            $driver = new \Doctrine\ORM\Mapping\Driver\YamlDriver($locator, '.dcm.yml');
            $driver->loadMetadataForClass($className, $outMetadata);

            $this->setCustomRepository($metadata, $outMetadata)
                ->setInheritance($metadata, $outMetadata)
                ->addFieldMappings($metadata, $outMetadata)
                ->addAssociationMappings($metadata, $outMetadata)
            // TODO: add here other stuff definable by the ORM
            ;
        }
    }
1325742
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        /** @var ClassMetadata $metadata */
        $metadata = $eventArgs->getClassMetadata();

        $reflectionClass = $metadata->getReflectionClass();

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

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

        // setting default mapping configuration for Labelable

        // name
        $metadata->mapField([
            'fieldName' => 'label',
            'type'      => 'string',
            'nullable'  => true,
        ]);

        $this->logger->debug(
            '[LabelableListener] Added Labelable mapping metadata to Entity',
            ['class' => $metadata->getName()]
        );
    }
152868
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $classMetadata = $eventArgs->getClassMetadata();
        if (MetadataLayer::isAlreadyProcessed($classMetadata)) {
            // we can skip it
            return;
        }

        $fieldNames = array_flip($classMetadata->getFieldNames());
        $reflectionClass = $classMetadata->getReflectionClass();

        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if (isset($fieldNames[$reflectionProperty->getName()])) {
                $this->loadHubProperty($reflectionProperty, $classMetadata);
            } else {
                $this->loadMaskProperty($reflectionProperty, $classMetadata);
            }
        }
    }
415772
public function preFlush(PreFlushEventArgs $args)
    {
        $entityManager = $args->getEntityManager();
        $scheduledInsertions = $entityManager
            ->getUnitOfWork()
            ->getScheduledEntityInsertions();

        $this
            ->categoryIntegrityFixer
            ->fixCategoriesIntegrityByArray($scheduledInsertions);
    }
852307
public function preUpdate(PreUpdateEventArgs $eventArgs): void
    {
        $object = $eventArgs->getObject();
        $this->gatherResourceAndItemTags($object, true);

        $changeSet = $eventArgs->getEntityChangeSet();
        $associationMappings = $eventArgs->getEntityManager()->getClassMetadata(ClassUtils::getClass($eventArgs->getObject()))->getAssociationMappings();

        foreach ($changeSet as $key => $value) {
            if (!isset($associationMappings[$key])) {
                continue;
            }

            $this->addTagsFor($value[0]);
            $this->addTagsFor($value[1]);
        }
    }
1354358
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();

        foreach ($uow->getScheduledEntityInsertions() as $entity) {
            if ($entity instanceof FileInterface){
                $this->populateMeta($em, $uow, $entity);
                $this->scheduledForCopyFiles[spl_object_hash($entity)] = $entity;
            }
        }

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

            if ($entity instanceof FileInterface){

                if ($this->versionEnabled){
                    $em->lock($entity, LockMode::OPTIMISTIC, $entity->getCurrentVersion());
                }
                
                if (true === $entity->isScheduledForDeletion()){
                    $uow->scheduleForDelete($entity);
                    continue;
                }
                
                $changeSet = $uow->getEntityChangeSet($entity);

                if (isset($changeSet['name'])){
                    // remove old file
                    $clonedEntity = clone $entity;
                    $clonedEntity->setName($changeSet['name'][0]);
                    $this->scheduledForDeleteFiles[spl_object_hash($clonedEntity)] = $clonedEntity;
                    $this->scheduledForCopyFiles[spl_object_hash($entity)] = $entity;
                    $this->checksum($entity);
                } 

                if(isset($changeSet['name']) || isset($changeSet['hash'])){
                    $this->populateMeta($em, $uow, $entity);
                }                
            }
        }

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            if ($entity instanceof FileInterface){
                $this->scheduledForDeleteFiles[spl_object_hash($entity)] = $entity;
            }
        }
    }
826928
private function updateViewReference(LifecycleEventArgs $eventArgs)
    {
        $entity = $eventArgs->getEntity();

        //if entity is a translation, get its translatable entity
        if (in_array(Translation::class, class_uses($entity)) && null !== $entity->getTranslatable()) {
            $entity = $entity->getTranslatable();
        }

        //if it's a businessEntity we need to rebuild virtuals (BPs are rebuild in businessEntitySubscriber)
        if ($businessEntity = $this->businessEntityHelper->findByEntityInstance($entity)) {
            $this->flushedBusinessEntities->add($entity);
        }
        //if it a businessTemplate we have to rebuild virtuals or update BP
        if ($entity instanceof BusinessTemplate) {
            $this->flushedBusinessTemplates->add($entity);
        }
    }
1061951
public function preUpdate(LifecycleEventArgs $eventArgs)
    {
        $entity = $eventArgs->getObject();

        if (!$this->hasTrait($entity, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
            return;
        }

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

        $now = new DateTime('NOW');
        $entity->setUpdatedAt($now);
    }
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 !');
            }
        }
    }
393895
public function onClear($eventArgs)
    {
        parent::onClear($eventArgs);

        $aliases = array_keys($this->identifierMap);

        $this->identifierMap = array_fill_keys($aliases, []);
    }
433466
protected function _triggerEvent($eventName, $entity, $eventArgs)
    {
        if (null === $this->_application) {
            return;
        }

        $dispatcher = $this->_application->getEventDispatcher();
        if (null !== $dispatcher) {
            $dispatcher->triggerEvent($eventName, $entity, $eventArgs);
        }
    }
577218
public function preFlush(PreFlushEventArgs $args)
    {
        $objectManager = $args->getEntityManager();
        $unitOfWork = $objectManager->getUnitOfWork();

        $entityMap = $unitOfWork->getIdentityMap();
        foreach ($entityMap as $objectClass => $objects) {
            if (in_array(UploadObjectInterface::class, class_implements($objectClass))) {
                foreach ($objects as $object) {
                    $this->prepareUploadFileReferences($object);
                }
            }
        }
    }
876117
public function onFlush(OnFlushEventArgs $args): void
    {
        $token = $this->getTokenStorage()->getToken();

        if (!$this->getPermissionManager()->isEnabled()
                || null === $token || $token instanceof ConsoleToken) {
            return;
        }

        $uow = $args->getEntityManager()->getUnitOfWork();
        $createEntities = $uow->getScheduledEntityInsertions();
        $updateEntities = $uow->getScheduledEntityUpdates();
        $deleteEntities = $uow->getScheduledEntityDeletions();

        $this->postResetPermissions = array_merge($createEntities, $updateEntities, $deleteEntities);
        $this->getPermissionManager()->preloadPermissions($this->postResetPermissions);

        $this->checkAllScheduledByAction($createEntities, 'create');
        $this->checkAllScheduledByAction($updateEntities, 'update');
        $this->checkAllScheduledByAction($deleteEntities, 'delete');
    }
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()]
        );
    }
904635
public function preFlush(PreFlushEventArgs $args)
    {
        foreach ($args->getEntityManager()->getUnitOfWork()->getScheduledEntityInsertions() as $entity) {
            $this->process($entity);
        }
    }