public function createUserGroup(APIUserGroupCreateStruct $userGroupCreateStruct, APIUserGroup $parentGroup)
{
$contentService = $this->repository->getContentService();
$locationService = $this->repository->getLocationService();
$contentTypeService = $this->repository->getContentTypeService();
if ($userGroupCreateStruct->contentType === null) {
$userGroupContentType = $contentTypeService->loadContentType($this->settings['userGroupClassID']);
$userGroupCreateStruct->contentType = $userGroupContentType;
}
$loadedParentGroup = $this->loadUserGroup($parentGroup->id);
if ($loadedParentGroup->getVersionInfo()->getContentInfo()->mainLocationId === null) {
throw new InvalidArgumentException('parentGroup', 'parent user group has no main location');
}
$locationCreateStruct = $locationService->newLocationCreateStruct($loadedParentGroup->getVersionInfo()->getContentInfo()->mainLocationId);
$this->repository->beginTransaction();
try {
$contentDraft = $contentService->createContent($userGroupCreateStruct, array($locationCreateStruct));
$publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->buildDomainUserGroupObject($publishedContent);
}