From b0ff21042f9e30b04e296c0a56b93ddc95e8596f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 26 Aug 2024 12:33:03 +0200 Subject: [PATCH] fix: Fix missing conflicts on pdf templating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/TemplateFieldService.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Service/TemplateFieldService.php b/lib/Service/TemplateFieldService.php index 5e0aafb529..112196c4a6 100644 --- a/lib/Service/TemplateFieldService.php +++ b/lib/Service/TemplateFieldService.php @@ -12,6 +12,7 @@ use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\Files\NotFoundException; use OCP\Files\Template\Field; use OCP\Files\Template\FieldType; use OCP\Http\Client\IClientService; @@ -46,12 +47,16 @@ public function extractFields(Node|int $file): array { } try { + if (!$file || !$file instanceof File) { + throw new NotFoundException(); + } + $localCache = $this->cacheFactory->createLocal('richdocuments_templates/'); $cacheName = $file->getId() . "/" . $file->getEtag(); $cachedResponse = $localCache->get($cacheName); - + if ($cachedResponse !== null) { - // return $cachedResponse; + return $cachedResponse; } if ($file->getMimeType() === 'application/pdf') { @@ -125,6 +130,13 @@ public function fillFields(Node|int $file, array $fields = [], ?string $destinat $file = $this->rootFolder->getFirstNodeById($file); } + if (!$file || !$file instanceof File) { + $e = new NotFoundException(); + $this->logger->error($e->getMessage()); + + throw $e; + } + if ($file->getMimeType() === 'application/pdf') { $content = $this->pdfService->fillFields($file, $fields); if ($destination !== null) {