<commit_before>﻿# -----------------------------------------------------------------------
# Copyright		: GSoft @2014
# Model  		: Standard Publishing CMS
# File          : Export-TermGroups.template.ps1
# Description	: Export Portal Taxonomy
# -----------------------------------------------------------------------

# Define working directory
$0 = $myInvocation.MyCommand.Definition
$CommandDirectory = [System.IO.Path]::GetDirectoryName($0)

#Prepare backup file
$BackupFolder = "$CommandDirectory\termgroups-backups"
if(!(Test-Path $BackupFolder)) 
{
	New-Item $BackupFolder -type directory
}

$DateStamp = (Get-Date -Format s) -replace ':', '.'
$ExportFilePath = "$BackupFolder\termgroups-$DateStamp.xml"

# Taxonomy Settings
$DefautNavigationtermGroup = "[[DSP_DEFAULT_PortalNavigationTermGroup]]"

$CustomNavigationTermGroup = "[[DSP_CUSTOM_PortalNavigationTermGroup]]"

$NavigationTermGroup = $DefautNavigationtermGroup

if(![string]::IsNullOrEmpty($CustomNavigationTermGroup))
{
	$NavigationTermGroup = $CustomNavigationTermGroup
}


$site = Get-SPSite "[[DSP_PortalPublishingHostNamePath]]"
if($site -eq $null)
{
	return
}

$taxonomySession = $site | Get-DSPTaxonomySession
if($taxonomySession -eq $null)
{
	return
}

$termStore = $taxonomySession | Get-DSPTermStore -Default
if($termStore -eq $null)
{
	return
}

# Portal Navigation Term Group
if($termStore.Groups[$NavigationTermGroup] -ne $null)
{
	Export-SPTerms -Group $termStore.Groups[$NavigationTermGroup] -OutputFile $ExportFilePath
}
else
{
	Write-Warning "Term Group $NavigationTermGroup doesn't exist. No export done."
}<commit_msg>[PUB01 Export] Fixed export-TermGroups script. - Won't crash when term group is not present<commit_after>﻿# -----------------------------------------------------------------------
# Copyright		: GSoft @2014
# Model  		: Standard Publishing CMS
# File          : Export-TermGroups.template.ps1
# Description	: Export Portal Taxonomy
# -----------------------------------------------------------------------

# Define working directory
$0 = $myInvocation.MyCommand.Definition
$CommandDirectory = [System.IO.Path]::GetDirectoryName($0)

#Prepare backup file
$BackupFolder = "$CommandDirectory\termgroups-backups"
if(!(Test-Path $BackupFolder)) 
{
	New-Item $BackupFolder -type directory
}

$DateStamp = (Get-Date -Format s) -replace ':', '.'
$ExportFilePath = "$BackupFolder\termgroups-$DateStamp.xml"

# Taxonomy Settings
$DefautNavigationtermGroup = "[[DSP_DEFAULT_PortalNavigationTermGroup]]"

$CustomNavigationTermGroup = "[[DSP_CUSTOM_PortalNavigationTermGroup]]"

$NavigationTermGroup = $DefautNavigationtermGroup

if(![string]::IsNullOrEmpty($CustomNavigationTermGroup))
{
	$NavigationTermGroup = $CustomNavigationTermGroup
}


$site = Get-SPSite "[[DSP_PortalPublishingHostNamePath]]"
if($site -eq $null)
{
	return
}

$taxonomySession = $site | Get-DSPTaxonomySession
if($taxonomySession -eq $null)
{
	return
}

$termStore = $taxonomySession | Get-DSPTermStore -Default
if($termStore -eq $null)
{
	return
}

# Portal Navigation Term Group
Try
{
    Export-SPTerms -Group $termStore.Groups[$NavigationTermGroup] -OutputFile $ExportFilePath -ErrorAction Stop
}
Catch
{
    Write-Warning "$_ No export done."
}
{'fraction_non_alphanumeric': 0.2015552099533437, 'fraction_numerical': 0.004976671850699844, 'mean_word_length': 3.523206751054852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5049534', 'n_tokens_mistral': 970, 'n_tokens_neox': 953, 'n_words': 195}