|
@@ 176-219 (lines=44) @@
|
| 173 |
|
* |
| 174 |
|
* @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup |
| 175 |
|
*/ |
| 176 |
|
public function updateObjectStateGroup(APIObjectStateGroup $objectStateGroup, ObjectStateGroupUpdateStruct $objectStateGroupUpdateStruct) |
| 177 |
|
{ |
| 178 |
|
if (!$this->repository->canUser('state', 'administrate', $objectStateGroup)) { |
| 179 |
|
throw new UnauthorizedException('state', 'administrate'); |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
$loadedObjectStateGroup = $this->loadObjectStateGroup($objectStateGroup->id); |
| 183 |
|
|
| 184 |
|
$inputStruct = $this->buildObjectStateGroupUpdateInputStruct( |
| 185 |
|
$loadedObjectStateGroup, |
| 186 |
|
$objectStateGroupUpdateStruct->identifier, |
| 187 |
|
$objectStateGroupUpdateStruct->defaultLanguageCode, |
| 188 |
|
$objectStateGroupUpdateStruct->names, |
| 189 |
|
$objectStateGroupUpdateStruct->descriptions |
| 190 |
|
); |
| 191 |
|
|
| 192 |
|
if ($objectStateGroupUpdateStruct->identifier !== null) { |
| 193 |
|
try { |
| 194 |
|
$existingObjectStateGroup = $this->objectStateHandler->loadGroupByIdentifier($inputStruct->identifier); |
| 195 |
|
if ($existingObjectStateGroup->id != $loadedObjectStateGroup->id) { |
| 196 |
|
throw new InvalidArgumentException( |
| 197 |
|
'objectStateGroupUpdateStruct', |
| 198 |
|
'Object state group with provided identifier already exists' |
| 199 |
|
); |
| 200 |
|
} |
| 201 |
|
} catch (APINotFoundException $e) { |
| 202 |
|
// Do nothing |
| 203 |
|
} |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
$this->repository->beginTransaction(); |
| 207 |
|
try { |
| 208 |
|
$spiObjectStateGroup = $this->objectStateHandler->updateGroup( |
| 209 |
|
$loadedObjectStateGroup->id, |
| 210 |
|
$inputStruct |
| 211 |
|
); |
| 212 |
|
$this->repository->commit(); |
| 213 |
|
} catch (Exception $e) { |
| 214 |
|
$this->repository->rollback(); |
| 215 |
|
throw $e; |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
return $this->buildDomainObjectStateGroupObject($spiObjectStateGroup); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
/** |
| 222 |
|
* Deletes a object state group including all states and links to content. |
|
@@ 328-375 (lines=48) @@
|
| 325 |
|
* |
| 326 |
|
* @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectState |
| 327 |
|
*/ |
| 328 |
|
public function updateObjectState(APIObjectState $objectState, ObjectStateUpdateStruct $objectStateUpdateStruct) |
| 329 |
|
{ |
| 330 |
|
if (!$this->repository->canUser('state', 'administrate', $objectState)) { |
| 331 |
|
throw new UnauthorizedException('state', 'administrate'); |
| 332 |
|
} |
| 333 |
|
|
| 334 |
|
$loadedObjectState = $this->loadObjectState($objectState->id); |
| 335 |
|
|
| 336 |
|
$inputStruct = $this->buildObjectStateUpdateInputStruct( |
| 337 |
|
$loadedObjectState, |
| 338 |
|
$objectStateUpdateStruct->identifier, |
| 339 |
|
$objectStateUpdateStruct->defaultLanguageCode, |
| 340 |
|
$objectStateUpdateStruct->names, |
| 341 |
|
$objectStateUpdateStruct->descriptions |
| 342 |
|
); |
| 343 |
|
|
| 344 |
|
if ($objectStateUpdateStruct->identifier !== null) { |
| 345 |
|
try { |
| 346 |
|
$existingObjectState = $this->objectStateHandler->loadByIdentifier( |
| 347 |
|
$inputStruct->identifier, |
| 348 |
|
$loadedObjectState->getObjectStateGroup()->id |
| 349 |
|
); |
| 350 |
|
|
| 351 |
|
if ($existingObjectState->id != $loadedObjectState->id) { |
| 352 |
|
throw new InvalidArgumentException( |
| 353 |
|
'objectStateUpdateStruct', |
| 354 |
|
'Object state with provided identifier already exists in provided object state group' |
| 355 |
|
); |
| 356 |
|
} |
| 357 |
|
} catch (APINotFoundException $e) { |
| 358 |
|
// Do nothing |
| 359 |
|
} |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
$this->repository->beginTransaction(); |
| 363 |
|
try { |
| 364 |
|
$spiObjectState = $this->objectStateHandler->update( |
| 365 |
|
$loadedObjectState->id, |
| 366 |
|
$inputStruct |
| 367 |
|
); |
| 368 |
|
$this->repository->commit(); |
| 369 |
|
} catch (Exception $e) { |
| 370 |
|
$this->repository->rollback(); |
| 371 |
|
throw $e; |
| 372 |
|
} |
| 373 |
|
|
| 374 |
|
return $this->buildDomainObjectStateObject($spiObjectState); |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
/** |
| 378 |
|
* Changes the priority of the state. |