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

setContentState() public method

Sets the object-state of a state group to $state for the given content.
public setContentState ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo, eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup, eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState )
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
$objectStateGroup eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup
$objectState eZ\Publish\API\Repository\Values\ObjectState\ObjectState
    public function setContentState(ContentInfo $contentInfo, APIObjectStateGroup $objectStateGroup, APIObjectState $objectState)
    {
        if ($this->repository->canUser('state', 'assign', $contentInfo, $objectState) !== true) {
            throw new UnauthorizedException('state', 'assign', array('contentId' => $contentInfo->id));
        }
        $loadedObjectState = $this->loadObjectState($objectState->id);
        if ($loadedObjectState->getObjectStateGroup()->id != $objectStateGroup->id) {
            throw new InvalidArgumentException('objectState', 'Object state does not belong to the given group');
        }
        $this->repository->beginTransaction();
        try {
            $this->objectStateHandler->setContentState($contentInfo->id, $objectStateGroup->id, $loadedObjectState->id);
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
    }