public function updateRole(APIRole $role, RoleUpdateStruct $roleUpdateStruct)
{
if ($roleUpdateStruct->identifier !== null && !is_string($roleUpdateStruct->identifier)) {
throw new InvalidArgumentValue('identifier', $roleUpdateStruct->identifier, 'RoleUpdateStruct');
}
$loadedRole = $this->loadRole($role->id);
if ($this->repository->hasAccess('role', 'update') !== true) {
throw new UnauthorizedException('role', 'update');
}
if ($roleUpdateStruct->identifier !== null) {
try {
$existingRole = $this->loadRoleByIdentifier($roleUpdateStruct->identifier);
if ($existingRole->id != $loadedRole->id) {
throw new InvalidArgumentException('$roleUpdateStruct', 'Role with provided identifier already exists');
}
} catch (APINotFoundException $e) {
// Do nothing
}
}
$this->repository->beginTransaction();
try {
$this->userHandler->updateRole(new SPIRoleUpdateStruct(array('id' => $loadedRole->id, 'identifier' => $roleUpdateStruct->identifier ?: $loadedRole->identifier)));
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->loadRole($loadedRole->id);
}