diff --git a/CHANGELOG.md b/CHANGELOG.md index f9f5a9b..6cba5d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## main -- Added a exception when the file is not found in a estate file query + +## v0.7.3 +- Added an exception when the file is not found in a estate file query +- Added a modify method for estate files ## v0.7.2 - Fixed a typo where the delete method of estate files returns an error diff --git a/src/Query/EstateFileBuilder.php b/src/Query/EstateFileBuilder.php index 11ce449..74d9674 100644 --- a/src/Query/EstateFileBuilder.php +++ b/src/Query/EstateFileBuilder.php @@ -102,7 +102,19 @@ public function each(callable $callback): void */ public function modify(int $id): bool { - throw new OnOfficeException('Not implemented'); + $parameters = array_replace($this->modifies, [ + 'fileId' => $id, + 'parentid' => $this->estateId, + 'relationtype' => 'estate', + ]); + + $response = $this->onOfficeService->requestApi( + OnOfficeAction::Modify, + OnOfficeResourceType::FileRelation, + parameters: $parameters, + ); + + return $response->json('response.results.0.data.records.0.elements.success') === 'success'; } /** diff --git a/src/Query/UploadBuilder.php b/src/Query/UploadBuilder.php index a4b88b8..14a98b3 100644 --- a/src/Query/UploadBuilder.php +++ b/src/Query/UploadBuilder.php @@ -83,30 +83,32 @@ public function save(string $fileContent): string } /** + * Returns the linked file data. + * * @throws OnOfficeException */ - public function link(string $tmpUploadId, array $data = []): self + public function link(string $tmpUploadId, array $data = []): array { $data = array_replace($data, [ 'tmpUploadId' => $tmpUploadId, ]); - $this->onOfficeService->requestApi( + $response = $this->onOfficeService->requestApi( OnOfficeAction::Do, OnOfficeResourceType::UploadFile, parameters: $data, ); - return $this; + return $response->json('response.results.0.data.records.0'); } /** * File content as base64-encoded binary data. - * Returns the temporary upload id. + * Returns the linked file data. * * @throws OnOfficeException */ - public function saveAndLink(string $fileContent, array $data = []): self + public function saveAndLink(string $fileContent, array $data = []): array { $tmpUploadId = $this->save($fileContent);