public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct)
{
if ($roleUpdateStruct->identifier !== null && !is_string($roleUpdateStruct->identifier)) {
throw new InvalidArgumentValue('identifier', $roleUpdateStruct->identifier, 'RoleUpdateStruct');
}
$loadedRoleDraft = $this->loadRoleDraft($roleDraft->id);
if ($this->repository->hasAccess('role', 'update') !== true) {
throw new UnauthorizedException('role', 'update');
}
if ($roleUpdateStruct->identifier !== null) {
try {
/* Throw exception if:
* - A published role with the same identifier exists, AND
* - The ID of the published role does not match the original ID of the draft
*/
$existingSPIRole = $this->userHandler->loadRoleByIdentifier($roleUpdateStruct->identifier);
$SPIRoleDraft = $this->userHandler->loadRole($loadedRoleDraft->id, Role::STATUS_DRAFT);
if ($existingSPIRole->id != $SPIRoleDraft->originalId) {
throw new InvalidArgumentException('$roleUpdateStruct', "Role '{$existingSPIRole->id}' with the specified identifier '{$roleUpdateStruct->identifier}' " . 'already exists');
}
} catch (APINotFoundException $e) {
// Do nothing
}
}
$this->repository->beginTransaction();
try {
$this->userHandler->updateRole(new SPIRoleUpdateStruct(array('id' => $loadedRoleDraft->id, 'identifier' => $roleUpdateStruct->identifier ?: $loadedRoleDraft->identifier)));
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->loadRoleDraft($loadedRoleDraft->id);
}