public function moveUserGroup(APIUserGroup $userGroup, APIUserGroup $newParent)
{
$loadedUserGroup = $this->loadUserGroup($userGroup->id);
$loadedNewParent = $this->loadUserGroup($newParent->id);
$locationService = $this->repository->getLocationService();
if ($loadedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId === null) {
throw new BadStateException('userGroup', 'existing user group is not stored and/or does not have any location yet');
}
if ($loadedNewParent->getVersionInfo()->getContentInfo()->mainLocationId === null) {
throw new BadStateException('newParent', 'new user group is not stored and/or does not have any location yet');
}
$userGroupMainLocation = $locationService->loadLocation($loadedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId);
$newParentMainLocation = $locationService->loadLocation($loadedNewParent->getVersionInfo()->getContentInfo()->mainLocationId);
$this->repository->beginTransaction();
try {
$locationService->moveSubtree($userGroupMainLocation, $newParentMainLocation);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}