/** * Updates object states of content * An object state in the input overrides the state of the object state group. * * @param $contentId * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * * @return \eZ\Publish\Core\REST\Common\Values\ContentObjectStates */ public function setObjectStatesForContent($contentId, Request $request) { $newObjectStates = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent())); $countByGroups = array(); foreach ($newObjectStates as $newObjectState) { $groupId = (int) $newObjectState->groupId; if (array_key_exists($groupId, $countByGroups)) { ++$countByGroups[$groupId]; } else { $countByGroups[$groupId] = 1; } } foreach ($countByGroups as $groupId => $count) { if ($count > 1) { throw new ForbiddenException("Multiple object states provided for group with ID {$groupId}"); } } $contentInfo = $this->contentService->loadContentInfo($contentId); $contentObjectStates = array(); foreach ($newObjectStates as $newObjectState) { $objectStateGroup = $this->objectStateService->loadObjectStateGroup($newObjectState->groupId); $this->objectStateService->setContentState($contentInfo, $objectStateGroup, $newObjectState->objectState); $contentObjectStates[(int) $objectStateGroup->id] = $newObjectState; } return new ContentObjectStates($contentObjectStates); }
/** * Sets the object-state of a state group to $state for the given content. * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state does not belong to the given group * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to change the object state * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState */ public function setContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup, ObjectState $objectState) { $returnValue = $this->service->setContentState($contentInfo, $objectStateGroup, $objectState); $this->signalDispatcher->emit(new SetContentStateSignal(array('contentId' => $contentInfo->id, 'objectStateGroupId' => $objectStateGroup->id, 'objectStateId' => $objectState->id))); return $returnValue; }