From d60b9706b3fee1cbbc4fb028753b5a09a3c08a2f Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 18 Feb 2021 08:58:55 +0200 Subject: [PATCH] cs fix --- application/Espo/Controllers/Attachment.php | 39 ++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/application/Espo/Controllers/Attachment.php b/application/Espo/Controllers/Attachment.php index bd499414c7..7ff5cf882c 100644 --- a/application/Espo/Controllers/Attachment.php +++ b/application/Espo/Controllers/Attachment.php @@ -29,31 +29,45 @@ namespace Espo\Controllers; -use Espo\Core\Exceptions\Forbidden; -use Espo\Core\Exceptions\BadRequest; +use Espo\Core\{ + Exceptions\Forbidden, + Exceptions\BadRequest, +}; -class Attachment extends \Espo\Core\Controllers\Record +use Espo\Core\Controllers\Record; + +class Attachment extends Record { public function actionList($params, $data, $request) { if (!$this->getUser()->isAdmin()) { throw new Forbidden(); } + return parent::actionList($params, $data, $request); } public function postActionGetAttachmentFromImageUrl($params, $data) { - if (empty($data->url)) throw new BadRequest(); - if (empty($data->field)) throw new BadRequest('postActionGetAttachmentFromImageUrl: No field specified'); + if (empty($data->url)) { + throw new BadRequest(); + } + + if (empty($data->field)) { + throw new BadRequest('postActionGetAttachmentFromImageUrl: No field specified'); + } return $this->getRecordService()->getAttachmentFromImageUrl($data)->getValueMap(); } public function postActionGetCopiedAttachment($params, $data) { - if (empty($data->id)) throw new BadRequest(); - if (empty($data->field)) throw new BadRequest('postActionGetCopiedAttachment copy: No field specified'); + if (empty($data->id)) { + throw new BadRequest(); + } + if (empty($data->field)) { + throw new BadRequest('postActionGetCopiedAttachment copy: No field specified'); + } return $this->getRecordService()->getCopiedAttachment($data)->getValueMap(); } @@ -62,12 +76,19 @@ class Attachment extends \Espo\Core\Controllers\Record { $id = $params['id'] ?? null; - if (!$id) throw new BadRequest(); + if (!$id) { + throw new BadRequest(); + } $fileData = $this->getRecordService()->getFileData($id); $response->setHeader('Content-Type', $fileData->type); - $response->setHeader('Content-Disposition', 'Content-Disposition: attachment; filename="'.$fileData->name.'"'); + + $response->setHeader( + 'Content-Disposition', + 'Content-Disposition: attachment; filename="' . $fileData->name . '"' + ); + if ($fileData->size) { $response->setHeader('Content-Length', strlen($fileData->contents)); }