public function preUpdate($eventArgs)
    {
        $entity = $eventArgs->getEntity();
        $changeset = $eventArgs->getEntityChangeSet();

        foreach ($this->metadata->getManagedFields($entity) as $field) {
            if (isset($changeset[$field])) {
                list($old, $new) = $changeset[$field];

                if ($old) {
                    $tempFilePath = $this->fileManager->getFilePath($entity, $field, $old);

                    if ($new && ((string)$new) && (string)$new == $tempFilePath) {
                        /** @var File $new */
                        // in this case the file was wrapped in a file object, but not actually changed.
                        // We "unwrap" the value here.
                        $new = $new->getBasename();
                    } else {
                        $filepath = $this->fileManager->getFilePath($entity, $field, $old);
                        $this->unitOfWork[spl_object_hash($entity)][$field]['delete'] =
                            function (FileManager $fm) use ($filepath) {
                                $fm->delete($filepath);
                            };
                    }
                }

                if (is_string($new)) {
                    $eventArgs->setNewValue($field, $new);
                } else {
                    if (null !== $new) {
                        $eventArgs->setNewValue($field, $this->scheduleForUpload($new, $entity, $field));
                    }
                }
            }
        }
    }
public function preUpdate($eventArgs)
    {
        $entity = $eventArgs->getEntity();
        $changeset = $eventArgs->getEntityChangeSet();

        foreach ($this->metadata->getManagedFields($entity) as $field) {
            if (isset($changeset[$field])) {
                list($old, $new) = $changeset[$field];

                if ($old) {
                    $tempFilePath = $this->fileManager->getFilePath($entity, $field, $old);

                    if ($new && ((string)$new) && (string)$new == $tempFilePath) {
                        /** @var File $new */
                        // in this case the file was wrapped in a file object, but not actually changed.
                        // We "unwrap" the value here.
                        $new = $new->getBasename();
                    } else {
                        $filepath = $this->fileManager->getFilePath($entity, $field, $old);
                        $this->unitOfWork[spl_object_hash($entity)][$field]['delete'] =
                            function (FileManager $fm) use ($filepath) {
                                $fm->delete($filepath);
                            };
                    }
                }

                if (is_string($new)) {
                    $eventArgs->setNewValue($field, $new);
                } else {
                    if (null !== $new) {
                        $eventArgs->setNewValue($field, $this->scheduleForUpload($new, $entity, $field));
                    }
                }
            }
        }
    }
public function preUpdate ( $ eventArgs ) { $ entity = $ eventArgs -> getEntity ( ) ; $ changeset = $ eventArgs -> getEntityChangeSet ( ) ; foreach ( $ this -> metadata -> getManagedFields ( $ entity ) as $ field ) { if ( isset ( $ changeset [ $ field ] ) ) { list ( $ old , $ new ) = $ changeset [ $ field ] ; if ( $ old ) { $ tempFilePath = $ this -> fileManager -> getFilePath ( $ entity , $ field , $ old ) ; if ( $ new && ( ( string ) $ new ) && ( string ) $ new == $ tempFilePath ) { /** @var File $new */ // in this case the file was wrapped in a file object, but not actually changed. // We "unwrap" the value here. $ new = $ new -> getBasename ( ) ; } else { $ filepath = $ this -> fileManager -> getFilePath ( $ entity , $ field , $ old ) ; $ this -> unitOfWork [ spl_object_hash ( $ entity ) ] [ $ field ] [ 'delete' ] = function ( FileManager $ fm ) use ( $ filepath ) { $ fm -> delete ( $ filepath ) ; } ; } } if ( is_string ( $ new ) ) { $ eventArgs -> setNewValue ( $ field , $ new ) ; } else { if ( null !== $ new ) { $ eventArgs -> setNewValue ( $ field , $ this -> scheduleForUpload ( $ new , $ entity , $ field ) ) ; } } } } }
Replaces a file value and removes the old file.

@param PreUpdateEventArgs $eventArgs
@return void
Replaces a file value and removes the old file .