/**
  * upload field and file data field are SAME ($obj->file)
  * @param EventArgs $args
  * @param PropertyMapping $mapping
  */
 protected function updateSeparateProperties(\Doctrine\Common\EventArgs $args, PropertyMapping $mapping)
 {
     $uploadedFile = $mapping->getFileUploadPropertyValue();
     $currentFileData = $mapping->getFileDataPropertyValue();
     $previousFileData = $this->dataStorage->previusFieldDataIfChanged($mapping->getFileDataPropertyName(), $args);
     $currentFileName = $previousFileData ? $mapping->resolveFileName($previousFileData['fileName']) : null;
     //delete current file
     if ($previousFileData && (is_null($currentFileData) || $uploadedFile && $uploadedFile instanceof \Iphp\FileStoreBundle\File\File && $uploadedFile->isDeleted())) {
         if ($this->fileStorage->removeFile($currentFileName)) {
             $mapping->setFileDataPropertyValue(null);
         }
     } else {
         if ($uploadedFile && $uploadedFile instanceof File) {
             //Old value (file) exists and uploaded new file
             if ($currentFileName && !$this->fileStorage->isSameFile($uploadedFile, $currentFileName)) {
                 //before upload new file delete old file
                 $this->fileStorage->removeFile($currentFileName);
             }
             $fileData = $this->fileStorage->upload($mapping, $uploadedFile);
             $mapping->setFileDataPropertyValue($fileData);
         }
     }
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function removeByMapping(PropertyMapping $mapping)
 {
     if ($mapping->getDeleteOnRemove()) {
         $fileData = $mapping->getFileDataPropertyValue();
         if ($fileData && file_exists($fileData['dir'] . '/' . $fileData['fileName'])) {
             @unlink($fileData['dir'] . '/' . $fileData['fileName']);
         }
     }
 }