public function updateObjectState(APIObjectState $objectState, ObjectStateUpdateStruct $objectStateUpdateStruct)
{
if ($this->repository->hasAccess('state', 'administrate') !== true) {
throw new UnauthorizedException('state', 'administrate');
}
$loadedObjectState = $this->loadObjectState($objectState->id);
$inputStruct = $this->buildObjectStateUpdateInputStruct($loadedObjectState, $objectStateUpdateStruct->identifier, $objectStateUpdateStruct->defaultLanguageCode, $objectStateUpdateStruct->names, $objectStateUpdateStruct->descriptions);
if ($objectStateUpdateStruct->identifier !== null) {
try {
$existingObjectState = $this->objectStateHandler->loadByIdentifier($inputStruct->identifier, $loadedObjectState->getObjectStateGroup()->id);
if ($existingObjectState->id != $loadedObjectState->id) {
throw new InvalidArgumentException('objectStateUpdateStruct', 'Object state with provided identifier already exists in provided object state group');
}
} catch (APINotFoundException $e) {
// Do nothing
}
}
$this->repository->beginTransaction();
try {
$spiObjectState = $this->objectStateHandler->update($loadedObjectState->id, $inputStruct);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->buildDomainObjectStateObject($spiObjectState);
}