/** * Updates an object state group. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update an object state group * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state group with provided identifier already exists * * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct $objectStateGroupUpdateStruct * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup */ public function updateObjectStateGroup(APIObjectStateGroup $objectStateGroup, ObjectStateGroupUpdateStruct $objectStateGroupUpdateStruct) { if ($this->repository->hasAccess('state', 'administrate') !== true) { throw new UnauthorizedException('state', 'administrate'); } $loadedObjectStateGroup = $this->loadObjectStateGroup($objectStateGroup->id); $inputStruct = $this->buildObjectStateGroupUpdateInputStruct($loadedObjectStateGroup, $objectStateGroupUpdateStruct->identifier, $objectStateGroupUpdateStruct->defaultLanguageCode, $objectStateGroupUpdateStruct->names, $objectStateGroupUpdateStruct->descriptions); if ($objectStateGroupUpdateStruct->identifier !== null) { try { $existingObjectStateGroup = $this->objectStateHandler->loadGroupByIdentifier($inputStruct->identifier); if ($existingObjectStateGroup->id != $loadedObjectStateGroup->id) { throw new InvalidArgumentException('objectStateGroupUpdateStruct', 'Object state group with provided identifier already exists'); } } catch (APINotFoundException $e) { // Do nothing } } $this->repository->beginTransaction(); try { $spiObjectStateGroup = $this->objectStateHandler->updateGroup($loadedObjectStateGroup->id, $inputStruct); $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } return $this->buildDomainObjectStateGroupObject($spiObjectStateGroup); }
/** * @covers \eZ\Publish\Core\Persistence\InMemory\ObjectStateHandler::updateGroup */ public function testUpdateGroup() { $updatedGroup = $this->handler->updateGroup(2, $this->getInputStructFixture()); $this->assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Group', $updatedGroup); $this->assertEquals(2, $updatedGroup->id); $this->assertEquals('test', $updatedGroup->identifier); $this->assertEquals('eng-US', $updatedGroup->defaultLanguage); $this->assertEquals(array('eng-US'), $updatedGroup->languageCodes); $this->assertEquals(array('eng-US' => 'Test'), $updatedGroup->name); $this->assertEquals(array('eng-US' => 'Test description'), $updatedGroup->description); }