From 7291c46d0d2e8c72f139d427fbf131f9dac452f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 30 Dec 2020 11:23:22 +0100 Subject: [PATCH] WIP work on delete/update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/AttachmentService.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 36ce4b7bc..1b98b9c11 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -272,8 +272,19 @@ class AttachmentService { * @throws NoPermissionException */ public function update($attachmentId, $data) { - if (is_numeric($attachmentId) === false) { - throw new BadRequestException('attachment id must be a number'); + if (!is_numeric($attachmentId)) { + [$type, $attachmentId] = explode(':', $attachmentId); + + try { + $attachment = new Attachment(); + $attachment->setId($attachmentId); + $attachment->setType($type); + $attachment->setData($data); + $service = $this->getService($type); + return $service->update($attachment); + } catch (\Exception $e) { + throw new NotFoundException(); + } } if ($data === false || $data === null) { @@ -321,8 +332,18 @@ class AttachmentService { * @throws BadRequestException */ public function delete($attachmentId) { - if (is_numeric($attachmentId) === false) { - throw new BadRequestException('attachment id must be a number'); + if (!is_numeric($attachmentId)) { + [$type, $attachmentId] = explode(':', $attachmentId); + + try { + $attachment = new Attachment(); + $attachment->setId($attachmentId); + $attachment->setType($type); + $service = $this->getService($type); + return $service->delete($attachment); + } catch (\Exception $e) { + throw new NotFoundException(); + } } try {