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;
            }
        }
    }
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;
            }
        }
    }
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 ; } } }
Handles onFlush event and moves file to permenant directory

@param OnFlushEventArgs $eventArgs
Handles onFlush event and moves file to permenant directory