/** * @Route( * "/download/file/{hash}", * name="diamante_attachment_file_download", * requirements={"hash"="\w+"} * ) * * @param string $hash * @return BinaryFileResponse */ public function fileAttachmentAction($hash) { $attachmentService = $this->get('diamante.attachment.service'); try { $attachment = $attachmentService->getByHash($hash); $attachmentDto = AttachmentDto::createFromAttachment($attachment); $response = $this->getFileDownloadResponse($attachmentDto); return $response; } catch (\Exception $e) { $this->container->get('monolog.logger.diamante')->error(sprintf('Attachment loading failed: %s', $e->getMessage())); throw $this->createNotFoundException('Attachment not found'); } }
/** * @Route( * "/download/file/{hash}", * name="diamante_attachment_file_download", * requirements={"hash"="\w+"} * ) * * @param string $hash * @return BinaryFileResponse */ public function fileAttachmentAction($hash) { $attachmentService = $this->get('diamante.attachment.service'); try { $attachment = $attachmentService->getByHash($hash); $attachmentDto = AttachmentDto::createFromAttachment($attachment); $response = $this->getFileDownloadResponse($attachmentDto); return $response; } catch (\Exception $e) { $this->handleException($e); throw $this->createNotFoundException('Attachment not found'); } }
/** * @Route( * "/attachment/download/ticket/{ticketId}/attachment/{attachId}", * name="diamante_ticket_attachment_download", * requirements={"ticketId"="\d+", "attachId"="\d+"} * ) * * @return BinaryFileResponse * @todo refactor download logic */ public function downloadAttachmentAction($ticketId, $attachId) { /** @var TicketService $ticketService */ $ticketService = $this->get('diamante.ticket.service'); $retrieveTicketAttachmentCommand = new RetrieveTicketAttachmentCommand(); $retrieveTicketAttachmentCommand->ticketId = $ticketId; $retrieveTicketAttachmentCommand->attachmentId = $attachId; try { $attachment = $ticketService->getTicketAttachment($retrieveTicketAttachmentCommand); $attachmentDto = AttachmentDto::createFromAttachment($attachment); $response = $this->getFileDownloadResponse($attachmentDto); return $response; } catch (\Exception $e) { $this->container->get('monolog.logger.diamante')->error(sprintf('Attachment retrieval failed: %s', $e->getMessage())); $this->addErrorMessage('diamante.desk.attachment.messages.get.error'); throw $this->createNotFoundException('Attachment not found'); } }
/** * @Route( * "/attachment/download/ticket/{ticketId}/attachment/{attachId}", * name="diamante_ticket_attachment_download", * requirements={"ticketId"="\d+", "attachId"="\d+"} * ) * * @return BinaryFileResponse * @todo refactor download logic */ public function downloadAttachmentAction($ticketId, $attachId) { $retrieveTicketAttachmentCommand = new RetrieveTicketAttachmentCommand(); $retrieveTicketAttachmentCommand->ticketId = $ticketId; $retrieveTicketAttachmentCommand->attachmentId = $attachId; try { $attachment = $this->get('diamante.ticket.service')->getTicketAttachment($retrieveTicketAttachmentCommand); $attachmentDto = AttachmentDto::createFromAttachment($attachment); $response = $this->getFileDownloadResponse($attachmentDto); return $response; } catch (\Exception $e) { $this->handleException($e); throw $this->createNotFoundException('Attachment not found'); } }