original_string: 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));
                      }
                  }
              }
          }
      }
code: 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));
                      }
                  }
              }
          }
      }
code_tokens: 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 ) ) ; } } } } }
docstring: Replaces a file value and removes the old file.
  
  @param PreUpdateEventArgs $eventArgs
  @return void
docstring_tokens: Replaces a file value and removes the old file .