From 5fcf994366a7be726ad058c6446ef2478b061e95 Mon Sep 17 00:00:00 2001 From: Orka Arnest CRUZE Date: Thu, 23 Nov 2023 16:49:09 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20modifie=20fa=C3=A7on=20d'envoyer=20les?= =?UTF-8?q?=20annexes=20(pb=20=C3=A0=20cause=20de=20FormData)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Services/EntrepotApi/AnnexeApiService.php | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Services/EntrepotApi/AnnexeApiService.php b/src/Services/EntrepotApi/AnnexeApiService.php index 5a7d8622..eb678fb8 100644 --- a/src/Services/EntrepotApi/AnnexeApiService.php +++ b/src/Services/EntrepotApi/AnnexeApiService.php @@ -31,19 +31,43 @@ public function get(string $datastoreId, string $annexeId): array * @param array $paths * @param array $labels */ - public function add(string $datastoreId, string $annexeFilePath, array $paths, array $labels = []): array + public function add(string $datastoreId, string $annexeFilePath, array $paths, array $labels = null, bool $published = true): array { $response = $this->sendFile('POST', "datastores/$datastoreId/annexes", $annexeFilePath, [ - 'published' => 'true', - 'paths' => $paths, - 'labels' => $labels, + 'published' => true === $published ? 'true' : 'false', + 'paths' => join(',', $paths), // ici on fait un join parce que c'est un FormData, qui ne gère pas bien les virgules ]); + $response = $this->modify($datastoreId, $response['_id'], null, $labels, null); + $this->filesystem->remove($annexeFilePath); return $response; } + /** + * @param array $paths + * @param array $labels + */ + public function modify(string $datastoreId, string $annexeId, array $paths = null, array $labels = null, bool $published = null): array + { + $body = []; + + if ($paths) { + $body['paths'] = $paths; + } + + if ($labels) { + $body['labels'] = $labels; + } + + if (null !== $published) { + $body['published'] = true === $published ? 'true' : 'false'; + } + + return $this->request('PATCH', "datastores/$datastoreId/annexes/$annexeId", $body); + } + public function replaceFile(string $datastoreId, string $annexeId, string $annexeFilePath): array { $response = $this->sendFile('PUT', "datastores/$datastoreId/annexes/$annexeId", $annexeFilePath);