diff --git a/lib/Service/TemplateFieldService.php b/lib/Service/TemplateFieldService.php index 5e0aafb529..4037acf9a1 100644 --- a/lib/Service/TemplateFieldService.php +++ b/lib/Service/TemplateFieldService.php @@ -46,12 +46,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 +129,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) {