diff --git a/lib/Service/ObjectService.php b/lib/Service/ObjectService.php index 9a5e022f..e0befbbf 100644 --- a/lib/Service/ObjectService.php +++ b/lib/Service/ObjectService.php @@ -304,13 +304,13 @@ public function getAllObjects(string $objectType, ?int $limit = null, ?int $offs */ public function saveObject(string $objectType, array $object, bool $updateVersion = true): mixed { - // Get the appropriate mapper for the object type - $mapper = $this->getMapper($objectType); - if ($objectType === 'publication') { $object = $this->validationService->validatePublication($object); } + // Get the appropriate mapper for the object type + $mapper = $this->getMapper($objectType); + // If the object has an id, update it; otherwise, create a new object if (isset($object['id']) === true) { return $mapper->updateFromArray($object['id'], $object, $updateVersion); diff --git a/lib/Service/ValidationService.php b/lib/Service/ValidationService.php index dc863d36..38371705 100644 --- a/lib/Service/ValidationService.php +++ b/lib/Service/ValidationService.php @@ -52,6 +52,10 @@ public function validatePublication(array $publication): array $validator = new Validator(); $validator->setMaxErrors(100); + if(empty($publicationType->getProperties()) === true) { + return $publication; + } + $result = $validator->validate(data: (object) json_decode(json_encode($publication['data'])), schema: $publicationType->getSchema($this->urlGenerator)); $publication['validation'] = [];