From 25a479aa4fccc505579cb8698f4b098ba4ee3b66 Mon Sep 17 00:00:00 2001 From: Elizabeth Danzberger Date: Tue, 9 Jul 2024 15:49:53 -0400 Subject: [PATCH] fix: `TemplateFieldService` can use either Node or file ID Signed-off-by: Elizabeth Danzberger --- lib/Service/TemplateFieldService.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Service/TemplateFieldService.php b/lib/Service/TemplateFieldService.php index 4346bae764..cdb87b5199 100644 --- a/lib/Service/TemplateFieldService.php +++ b/lib/Service/TemplateFieldService.php @@ -8,23 +8,30 @@ namespace OCA\Richdocuments\Service; use OCA\Richdocuments\AppConfig; +use OCA\Richdocuments\TemplateManager; use OCP\Files\Node; use OCP\Http\Client\IClientService; class TemplateFieldService { private IClientService $clientService; private AppConfig $appConfig; + private TemplateManager $templateManager; public function __construct( IClientService $clientService, - AppConfig $appConfig + AppConfig $appConfig, + TemplateManager $templateManager ) { $this->clientService = $clientService; $this->appConfig = $appConfig; + $this->templateManager = $templateManager; } - public function extractFields(Node $file): ?array { - // TODO: Won't work until Collabora's endpoint is ready + public function extractFields(Node|int $file): ?array { + if (is_int($file)) { + $file = $this->templateManager->get($file); + } + $collaboraUrl = $this->appConfig->getCollaboraUrlInternal(); $httpClient = $this->clientService->newClient(); @@ -36,11 +43,16 @@ public function extractFields(Node $file): ?array { return [$response->getBody()]; } catch (\Exception $e) { + // handle exception return null; } } - public function fillFields(Node $file, array $fieldValues): void { + public function fillFields(Node|int $file, array $fieldValues): void { + if (is_int($file)) { + $file = $this->templateManager->get($file); + } + $collaboraUrl = $this->appConfig->getCollaboraUrlInternal(); $httpClient = $this->clientService->newClient();