예제 #1
0
 /**
  * Update attachment entity before upload
  *
  * @param File $entity
  */
 public function preUpload(File $entity)
 {
     if ($entity->isEmptyFile()) {
         if ($entity->getFilename() !== null && $this->filesystem->has($entity->getFilename())) {
             $this->filesystem->delete($entity->getFilename());
         }
         $entity->setFilename(null);
         $entity->setExtension(null);
         $entity->setOriginalFilename(null);
     }
     if ($entity->getFile() !== null && $entity->getFile()->isFile()) {
         $entity->setOwner($this->securityFacadeLink->getService()->getLoggedUser());
         $file = $entity->getFile();
         if ($entity->getFilename() !== null && $this->filesystem->has($entity->getFilename())) {
             $this->filesystem->delete($entity->getFilename());
         }
         $entity->setExtension($file->guessExtension());
         if ($file instanceof UploadedFile) {
             $entity->setOriginalFilename($file->getClientOriginalName());
             $entity->setMimeType($file->getClientMimeType());
             $entity->setFileSize($file->getClientSize());
         } else {
             $entity->setOriginalFilename($file->getFileName());
             $entity->setMimeType($file->getMimeType());
             $entity->setFileSize($file->getSize());
         }
         $entity->setFilename($this->generateFileName($entity->getExtension()));
         $fsAdapter = $this->filesystem->getAdapter();
         if ($fsAdapter instanceof MetadataSupporter) {
             $fsAdapter->setMetadata($entity->getFilename(), ['contentType' => $entity->getMimeType()]);
         }
     }
 }
예제 #2
0
 /**
  * @param EmailAttachment $emailAttachment
  *
  * @return File|null
  */
 protected function copyEmailAttachmentToFileSystem(EmailAttachment $emailAttachment)
 {
     $file = new File();
     $file->setExtension($emailAttachment->getExtension());
     $file->setOriginalFilename($emailAttachment->getFileName());
     $file->setMimeType($emailAttachment->getContentType());
     $file->setFilename(uniqid() . '.' . $file->getExtension());
     $content = ContentDecoder::decode($emailAttachment->getContent()->getContent(), $emailAttachment->getContent()->getContentTransferEncoding());
     $this->filesystem->write($file->getFilename(), $content);
     $f = new ComponentFile($this->getAttachmentFullPath($file->getFilename()));
     $file->setFile($f);
     $file->setFileSize($f->getSize());
     $file->setUploaded(false);
     $file->setOwner($this->securityFacadeLink->getService()->getLoggedUser());
     return $file;
 }