Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Matter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions src/Model/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
]);
}
}
31 changes: 31 additions & 0 deletions src/Model/PartyReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace ItkDev\F2ApiClient\Model;

final class PartyReference extends AbstractF2Item
{
// @see resources/f2-rest-docs/f2-rest-docs-v13s.html#38
public ?string $email = null;
// The login name of an F2 user
public ?string $login = null;
// Party number as found in the F2 party registry.
public ?int $partyNo = null;

#[\Override]
public function __toString(): string
{
return sprintf('PartyReference %s (%s)', $this->login, $this->partyNo);
}

#[\Override]
public function apiSerialize(): array
{
return array_filter([
'Email' => $this->email,
'Login' => $this->login,
'PartyNo' => $this->partyNo,
]);
}
}
Loading