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);