eZ\Publish\Core\Repository\ObjectStateService::updateObjectState PHP Method

updateObjectState() public method

Updates an object state.
public updateObjectState ( eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState, eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct $objectStateUpdateStruct ) : eZ\Publish\API\Repository\Values\ObjectState\ObjectState
$objectState eZ\Publish\API\Repository\Values\ObjectState\ObjectState
$objectStateUpdateStruct eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct
return eZ\Publish\API\Repository\Values\ObjectState\ObjectState
    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);
    }