function testReverseTransformNoDeleteFile()
 {
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $file = Mocks::getFileMock($this);
     $this->transformer->setMapping($propertyMapping, FileDataTransformer::MODE_UPLOAD_FIELD);
     $this->fileStorage->expects($this->never())->method('removeFile');
     $this->assertSame($this->transformer->reverseTransform(array('delete' => 0, 'file' => $file, 'fileName' => '123.jpg')), $file);
 }
예제 #2
0
 /**
  * Removes the file if necessary.
  *
  * @param \Doctrine\ORM\Event\LifecycleEventArgs $args The event arguments.
  */
 public function postRemove(LifecycleEventArgs $args)
 {
     $mappings = $this->mappingFactory->fromEventArgs($args);
     foreach ($mappings as $mapping) {
         $this->fileStorage->removeByMapping($mapping);
     }
 }
 /**
  * Removes the file if necessary.
  *
  * @param \Doctrine\Common\EventArgs $args The event arguments.
  */
 public function postRemove(EventArgs $args)
 {
     $mappings = $this->getMappingsFromArgs($args);
     foreach ($mappings as $mapping) {
         if ($mapping->getDeleteOnRemove()) {
             $this->fileStorage->removeFile($mapping->resolveFileName());
         }
     }
 }
 /**
  * array with 2 items - file (UploadedFile) and delete (checkbox)
  * @param $fileDataFromForm
  * @return int
  */
 public function reverseTransform($fileDataFromForm)
 {
     //if file field != file upload field - no need to store 'delete' in serialized file data
     if (isset($fileDataFromForm['delete']) && !$fileDataFromForm['delete']) {
         unset($fileDataFromForm['delete']);
     }
     if ($this->mapping && isset($fileDataFromForm['delete']) && $fileDataFromForm['delete']) {
         if ($this->mode == self::MODE_FILEDATA_FIELD) {
             return null;
         }
         //Todo: move to uploaderListener
         //File may no exists
         try {
             $this->fileStorage->removeFile($this->mapping->resolveFileName($fileDataFromForm['fileName']));
         } catch (\Exception $e) {
         }
     }
     return isset($fileDataFromForm['file']) ? $fileDataFromForm['file'] : ($this->mode == self::MODE_UPLOAD_FIELD ? null : $fileDataFromForm);
 }
 public function testPostRemoveNoDelete()
 {
     $obj = new DummyEntity();
     $args = Mocks::getEventArgsMock($this);
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $this->setDataStorageObjectMapping($obj, $propertyMapping);
     $propertyMapping->expects($this->once())->method('getDeleteOnRemove')->will($this->returnValue(false));
     $this->fileStorage->expects($this->never())->method('removeFile');
     $listener = $this->getUploaderListener();
     $listener->postRemove($args);
 }
예제 #6
0
 /**
  * Обработать мультиязычную загрузку файла
  * и получить подготовленные данные для сохранения
  * @param string $value - значение пришедшее из формы
  * @param string $field - обрабатываемое поле
  * @param string $locale - локаль
  * @param object $entity - сущность которая сохраняется
  * @return array|null
  */
 protected function processFileUpload($value, $field, $locale, $entity)
 {
     $result = false;
     if (isset($value['delete']) && $value['delete']) {
         $this->deleteFileByOldData($value, $field, $entity);
         //чтобы фронт не ломался и не было NOTICE в iPhp
         $result = ['fileName' => null, 'originalName' => null, 'mimeType' => null, 'size' => null, 'path' => null];
     } elseif (isset($value['file']) && $value['file'] instanceof File) {
         // Локаль указвыается в сущности для того,
         // чтобы её можно было использовать
         // при формировании имени файла
         $entity->setLocale($locale);
         $fileMapping = $this->getFileMappings($entity)[$field];
         $fileData = $this->fileStorage->upload($fileMapping, $value['file']);
         //Сбрасываем локаль
         $entity->setLocale(null);
         $result = $fileData;
     } elseif (isset($value['oldData'])) {
         $result = unserialize($value['oldData']);
     }
     return $result;
 }
 public function needResolveCollision($fileName, FileStorageInterface $fileStorage)
 {
     //print "\n -->".$fileName;
     return !$this->isOverwriteDuplicates() && $fileStorage->fileExists($this->resolveFileName($fileName));
 }