Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to update as patch #73

Merged
merged 2 commits into from
Nov 28, 2024
Merged
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
11 changes: 9 additions & 2 deletions lib/Service/ObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,18 @@ public function createFromArray(array $object) {
* @param bool $updatedObject Whether this is an update operation
* @return ObjectEntity The updated object
*/
public function updateFromArray(string $id, array $object, bool $updatedObject) {
public function updateFromArray(string $id, array $object, bool $updatedObject, bool $patch = false) {
// Add ID to object data for update
$object['id'] = $id;

return $this->saveObject(
// If we want the update to behave like patch, merge with existing object.
if ($patch === true) {
$oldObject = $this->getObject($this->registerMapper->find($this->getRegister()), $this->schemaMapper->find($this->getSchema()), $id)->jsonSerialize();

$object = array_merge($oldObject, $object);
}

return $this->saveObject(
register: $this->getRegister(),
schema: $this->getSchema(),
object: $object
Expand Down