Check and eventually update files keys.

@param PreFlushEventArgs $eventArgs
500692
public function preFlush(PreFlushEventArgs $eventArgs)
    {
        $entityManager = $eventArgs->getEntityManager();
        $unitOfWork = $entityManager->getUnitOfWork();

        foreach ($unitOfWork->getIdentityMap() as $entities) {
            foreach ($entities as $object) {
                $uploadableMeta = $this->getObjectExtendedMetadata($entityManager, $object);
                if (!$uploadableMeta->hasUploadableProperties()) {
                    continue;
                }
                $this->updateFiles($entityManager, $object, $uploadableMeta);
            }
        }
    }
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();
    }
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);
        }
    }
187109
public function preUpdate(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof MediaInterface) {
            $this->getProvider($args)->preUpdate($args->getObject());
        }
    }
1336456
public function postLoad($eventArgs)
    {
        if (!method_exists($eventArgs, 'getObject')) {
            throw new \InvalidArgumentException('$eventArgs must implement a `getObject` method');
        }

        $object = $eventArgs->getObject();

        $classList = array_keys($this->externalAssociationList);
        foreach ($classList as $className) {
            if (is_a($object, $className)) {
                $blendList = $this->externalAssociationList[$className];
                foreach ($blendList as $blend) {
                    $identifier = $object->{$blend->getReferenceIdGetter()}();

                    if ($identifier) {

                        $setter = $blend->getReferenceSetter();

                        if (is_array($identifier) || $identifier instanceof Traversable) {
                            $referenceList = [];
                            foreach ($identifier as $scalarIdentifier) {
                                $referenceList[] = $blend->getReferenceManager()
                                ->getReference($blend->getReferenceClassName(), $scalarIdentifier);
                            }
                            $object->{$setter}($referenceList);

                        } else {
                            $reference = $blend->getReferenceManager()
                                ->getReference($blend->getReferenceClassName(), $identifier);

                            $object->{$setter}($reference);
                        }
                    }
                }
            }
        }
    }
114751
public static function updateFiles(Event $event, $files, array $info)
    {
        // start
        $io = $event->getIO();
        if ($io->askConfirmation('Jumpstart will now update your files with the provided information. Okay? [yes]:' . "\t")) {
            foreach ($files as $file) {
                $file = array_pop($file);
                $io->write("\t" . $file . "\t", false);
                $io->write(static::updateFile($file, $info) ? 'OK' : 'Error');
            }
            if (file_exists('plugin.php')) {
                rename('plugin.php', $info['plugin_slug'] . '.php');
            }
            $io->write('');
        }
    }
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);
    }
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);
        }
    }
130055
public function preFlush(PreFlushEventArgs $args)
    {
        $scheduledInsertions = $args
            ->getEntityManager()
            ->getUnitOfWork()
            ->getScheduledEntityInsertions();

        foreach ($scheduledInsertions as $entity) {
            if ($entity instanceof CategoryInterface) {
                $this->removeParentCategoryForRootCategory($entity);
            }
        }

        return $this;
    }
1188834
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $this->pages = new ArrayCollection();

        $this->manager = $eventArgs->getEntityManager();
        $uow = $this->manager->getUnitOfWork();

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            $this->handleEntity($entity);
        }
        /** @var \Doctrine\Common\Collections\ArrayCollection $col */
        foreach ($uow->getScheduledCollectionUpdates() as $col) {
            foreach ($col as $entity) {
                $this->handleEntity($entity);
            }
        }

        if (0 < $this->pages->count()) {
            $this->persister->replaceMany($this->pages->toArray());
        }
    }
505578
public function preFlush(PreFlushEventArgs $event)
    {
        $entityManager = $event->getEntityManager();
        $uow = $entityManager->getUnitOfWork();

        foreach ($uow->getIdentityMap() as $class => $entities) {
            foreach ($entities as $entity) {
                if ($entity instanceof DeletableInterface) {
                    if ($entity->isDeleted()) {
                        $entityManager->remove($entity);
                    }
                }
            }
        }
    }
1107619
public function preFlushModifiedAt(\Doctrine\ORM\Event\PreFlushEventArgs $args) : self
    {
        if (is_null($this->getModifiedAt())) {
            $this->setModifiedAt(new \DateTime('now'));
        }

        return $this;
    }
323808
public function prePersist($eventArgs)
    {
        $entity = $eventArgs->getEntity();

        foreach ($this->metadata->getManagedFields($entity) as $field) {
            $value = PropertyHelper::getValue($entity, $field);
            if (null !== $value) {
                $this->scheduleForUpload($value, $entity, $field);
            }
        }
    }
1005495
public function onFlush(OnFlushEventArgs $args): void
    {
        $token = $this->getTokenStorage()->getToken();

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

        $uow = $args->getEntityManager()->getUnitOfWork();
        $this->getObjectFilter()->beginTransaction();

        $this->checkAllScheduledByAction($uow->getScheduledEntityInsertions(), 'create');
        $this->checkAllScheduledByAction($uow->getScheduledEntityUpdates(), 'edit');
        $this->checkAllScheduledByAction($uow->getScheduledEntityDeletions(), 'delete');

        $this->getObjectFilter()->commit();
    }
265931
public function afterUpdate(array &$args) {
        foreach ($this->_affectedRows as $row) {
            foreach ($this->_newValues as $key => $value) {
                // compare the old and new values
                if ($row->$key != $value) {
                    $this->_deleteFile($row->$key);
                }
            }
        }
    }
1281594
public function preRemove($eventArgs)
    {
        $entity = $eventArgs->getEntity();
        foreach ($this->metadata->getManagedFields($entity) as $field) {
            $file = PropertyHelper::getValue($entity, $field);

            if ($file) {
                $filepath = $this->fileManager->getFilePath($entity, $field, $file);

                $this->unitOfWork[spl_object_hash($entity)][$field]['delete'] = function (FileManager $fm) use ($filepath) {
                    $fm->delete($filepath);
                };
            }
        }
    }
1154090
public function preUpdate(PreUpdateEventArgs $args) {
        $reflectionClass = new ReflectionClass($args->getEntity());
        $properties = $reflectionClass->getProperties();
        foreach ($properties as $refProperty) {
            if ($this->annReader->getPropertyAnnotation($refProperty, self::ENCRYPTED_ANN_NAME)) {
                $propName = $refProperty->getName();
                $args->setNewValue($propName, $this->encryptor->encrypt($args->getNewValue($propName)));
            }
        }
    }