/** * 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::update */ public function testUpdate() { $updatedState = $this->handler->update(1, $this->getInputStructFixture()); $this->assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState', $updatedState); $this->assertEquals(1, $updatedState->id); $this->assertEquals(2, $updatedState->groupId); $this->assertEquals('test', $updatedState->identifier); $this->assertEquals('eng-US', $updatedState->defaultLanguage); $this->assertEquals(array('eng-US'), $updatedState->languageCodes); $this->assertEquals(array('eng-US' => 'Test'), $updatedState->name); $this->assertEquals(array('eng-US' => 'Test description'), $updatedState->description); $this->assertEquals(0, $updatedState->priority); }