/**
  * Create new attachment and assign it to the attachment holder
  * @param string $filename
  * @param string $content
  * @param AttachmentHolder $holder
  * @return \Diamante\DeskBundle\Model\Attachment\Attachment
  */
 public function createNewAttachment($filename, $content, AttachmentHolder $holder)
 {
     $this->validateFilename($filename);
     $this->validateContent($content);
     $filenamePrefix = $this->exposeFilenamePrefixFrom($holder);
     $path = $this->fileStorageService->upload($filenamePrefix . '/' . $filename, $content);
     $file = new File($path);
     $hash = $this->generateFileHash($file);
     if ($this->isImage($file)) {
         $this->createThumbnail($file, $hash, $filenamePrefix);
     }
     $attachment = $this->factory->create($file, $hash);
     $holder->addAttachment($attachment);
     $this->repository->store($attachment);
     return $attachment;
 }
 /**
  * Create new attachment and assign it to the attachment holder
  * @param string $filename
  * @param string $content
  * @param AttachmentHolder $holder
  * @param bool $flush
  * @return Attachment
  */
 public function createNewAttachment($filename, $content, AttachmentHolder $holder, $flush = false)
 {
     $this->validateFilename($filename);
     $this->validateContent($content);
     $filename = urldecode($filename);
     $filenamePrefix = $this->exposeFilenamePrefixFrom($holder);
     $path = $this->fileStorageService->upload($filenamePrefix . '/' . $filename, $content);
     $file = new File($path);
     $hash = $this->generateFileHash($file);
     if ($this->isImage($file)) {
         $this->createThumbnail($file, $hash, $filenamePrefix);
     }
     $attachment = $this->factory->create($file, $hash);
     $holder->addAttachment($attachment);
     $this->registry->getManager()->persist($attachment);
     if (true === $flush) {
         $this->registry->getManager()->flush();
     }
     return $attachment;
 }