/** * Updates an object state. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update an object state * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state with provided identifier already exists in the same group * * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct $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); }
/** * @covers \eZ\Publish\Core\Persistence\InMemory\ObjectStateHandler::loadByIdentifier * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException */ public function testLoadByIdentifierThrowsNotFoundException() { $this->handler->loadByIdentifier('unknown', 2); }