From 2810ff10bc7e7a52cd4db70f28c209b3e01ae36b Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Mon, 30 Nov 2026 09:47:32 +0100 Subject: [PATCH 1/2] Added document metadata and some check when updating document content --- src/ApiClient.php | 34 ++++++++++++++++++++++------------ src/Model/Document.php | 6 ++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/ApiClient.php b/src/ApiClient.php index b725fab..7e245fb 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -372,20 +372,17 @@ public function documentCreate(Document $document, string $filename, Matter $mat public function documentUpdate(Document $document, Document $updatedDocument, ?string $filename = null): bool { - $url = $document->links->getUrl('self'); - $diff = $this->computeDiff($document, $updatedDocument); - if ($diff->getDiffCnt() > 0) { - $response = $this->request(Request::METHOD_PATCH, $url, [ - 'json' => $diff->getPatch()->jsonSerialize(), - ]); - - if (Response::HTTP_OK !== $response->getStatusCode()) { - $message = sprintf('Cannot update document %s', $document); - throw $this->createRuntimeException($message, response: $response); + if (null !== $filename) { + // Check that (content) type of new file content matches original content + $fileType = pathinfo($filename, PATHINFO_EXTENSION); + if ($fileType !== $document->fileType) { + $message = sprintf('Cannot upload file %s of type %s on document %s with type %s', + basename($filename), $fileType, + $document, $document->fileType, + ); + throw $this->createRuntimeException($message); } - } - if (null !== $filename) { $fileHandle = fopen($filename, 'r'); if (false === $fileHandle) { $message = sprintf('Cannot open document file %s', $filename); @@ -410,6 +407,19 @@ public function documentUpdate(Document $document, Document $updatedDocument, ?s } } + $url = $document->links->getUrl('self'); + $diff = $this->computeDiff($document, $updatedDocument); + if ($diff->getDiffCnt() > 0) { + $response = $this->request(Request::METHOD_PATCH, $url, [ + 'json' => $diff->getPatch()->jsonSerialize(), + ]); + + if (Response::HTTP_OK !== $response->getStatusCode()) { + $message = sprintf('Cannot update document %s', $document); + throw $this->createRuntimeException($message, response: $response); + } + } + return true; } diff --git a/src/Model/Document.php b/src/Model/Document.php index 6e4eec1..4a903ff 100644 --- a/src/Model/Document.php +++ b/src/Model/Document.php @@ -10,6 +10,9 @@ final class Document extends AbstractF2Item public string $title; public string $description = ''; + public string $fileType = ''; + public string $contentType = ''; + public int $size = 0; public ?\DateTimeImmutable $createdDate = null; public ?\DateTimeImmutable $modifiedDate = null; @@ -22,6 +25,9 @@ public function setFromSimpleXMLElement(\SimpleXMLElement $sxe): static $this->id = (int) $sxe->Id; $this->title = (string) $sxe->Title; $this->description = (string) $sxe->Description; + $this->fileType = (string) $sxe->FileType; + $this->contentType = (string) $sxe->ContentType; + $this->size = (int) $sxe->Size; $this->createdDate = $this->createDateTime($sxe->CreatedDate); $this->modifiedDate = $this->createDateTime($sxe->ModifiedDate); From 671a7e30847b80a0c3c13388c77664ccd0563d63 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Wed, 2 Dec 2026 10:24:56 +0100 Subject: [PATCH 2/2] Added PartyReference model --- src/Model/Matter.php | 2 +- src/Model/Party.php | 12 ++++++------ src/Model/PartyReference.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/Model/PartyReference.php diff --git a/src/Model/Matter.php b/src/Model/Matter.php index f5be7b1..bcf9e35 100644 --- a/src/Model/Matter.php +++ b/src/Model/Matter.php @@ -23,7 +23,7 @@ final class Matter extends AbstractF2Item public ?\DateTimeImmutable $modifiedDate = null; public ?Party $createdBy = null; public ?Party $modifiedBy = null; - public ?Party $responsible = null; + public Party|PartyReference|null $responsible = null; // @mago-ignore analysis:non-documented-property #[\Override] diff --git a/src/Model/Party.php b/src/Model/Party.php index 9f70274..6a3b7e7 100644 --- a/src/Model/Party.php +++ b/src/Model/Party.php @@ -6,11 +6,11 @@ final class Party extends AbstractF2Item { - // @see resources/f2-rest-docs/f2-rest-docs-v13s.html#56 - + // @see resources/f2-rest-docs/f2-rest-docs-v13s.html#35 public ?string $name = null; public ?string $email = null; public ?string $type = null; + // Internal identifier of party - displayed in F2 party details window public ?int $partyNumber = null; // @mago-ignore analysis:non-documented-property @@ -38,10 +38,10 @@ public function __toString(): string public function apiSerialize(): array { return array_filter([ - 'name' => $this->name, - 'email' => $this->email, - 'type' => $this->type, - 'partyNumber' => $this->partyNumber, + 'Name' => $this->name, + 'Email' => $this->email, + 'Type' => $this->type, + 'PartyNumber' => $this->partyNumber, ]); } } diff --git a/src/Model/PartyReference.php b/src/Model/PartyReference.php new file mode 100644 index 0000000..c1af886 --- /dev/null +++ b/src/Model/PartyReference.php @@ -0,0 +1,31 @@ +login, $this->partyNo); + } + + #[\Override] + public function apiSerialize(): array + { + return array_filter([ + 'Email' => $this->email, + 'Login' => $this->login, + 'PartyNo' => $this->partyNo, + ]); + } +}