|
[CmdletBinding(SupportsShouldProcess)] |
|
Param( |
|
[Parameter()] |
|
[ValidateScript({ Test-Path $_ -PathType "Container" })] |
|
[string]$SolrInstallDir = "C:\solr-7.5.0" |
|
, |
|
[Parameter()] |
|
[ValidateNotNull()] |
|
[string]$SolrServiceName = "*solr*" |
|
, |
|
[Parameter()] |
|
[ValidateNotNull()] |
|
[string[]]$Indexes = @( |
|
"sitecore_analytics_index" |
|
"sitecore_core_index" |
|
"sitecore_fxm_master_index" |
|
"sitecore_fxm_web_index" |
|
"sitecore_list_index" |
|
"sitecore_marketing_asset_index_master" |
|
"sitecore_marketing_asset_index_web" |
|
"sitecore_marketingdefinitions_master" |
|
"sitecore_marketingdefinitions_web" |
|
"sitecore_master_index" |
|
"sitecore_suggested_test_index" |
|
"sitecore_testing_index" |
|
"sitecore_web_index" |
|
"social_messages_master" |
|
"social_messages_web" |
|
) |
|
, |
|
[Parameter()] |
|
[ValidateScript({ Test-Path (Join-Path $SolrInstallDir -ChildPath "server\solr\configsets\${_}") -PathType "Container" })] |
|
[string]$ConfigSet = "_default" # use "basic_configs <= SOLR 6.6 |
|
) |
|
Begin { |
|
$_eap = $ErrorActionPreference |
|
$ErrorActionPreference = "Stop" |
|
} |
|
Process { |
|
$solrService = Get-Service $SolrServiceName -ErrorAction SilentlyContinue |
|
If ($null -eq $solrService) { |
|
Write-Error "SOLR service not found." |
|
} |
|
|
|
Write-Host "Stopping SOLR service ($($solrService.Name))" |
|
Stop-Service $solrService.Name |
|
|
|
$configSetSource = Join-Path $SolrInstallDir -ChildPath "server\solr\configsets\${ConfigSet}" |
|
$configSetDest = Join-Path $SolrInstallDir -ChildPath "server\solr" |
|
|
|
$Indexes | ForEach-Object { |
|
$index = $_ |
|
$indexDest = Join-Path $configSetDest -ChildPath $index |
|
$managedSchema = Join-Path $indexDest -ChildPath "conf\managed-schema" |
|
$managedSchemaBackup = "${managedSchema}.bak" |
|
|
|
Write-Host "Processing ${index}..." |
|
|
|
If (!(Test-Path $indexDest)) { |
|
Write-Host " Copying files to ${indexDest}" |
|
Copy-Item $configSetSource -Destination $indexDest -Recurse -Container |
|
} Else { |
|
Write-Host " Index already found, skipping copy." |
|
} |
|
|
|
If ($PSCmdlet.ShouldProcess($managedSchema, "Backup") -and !(Test-Path $managedSchemaBackup)) { |
|
Write-Host " Backing up managed-schema" |
|
Move-Item $managedSchema -Destination "${managedSchema}.bak" |
|
} |
|
|
|
If ($PSCmdlet.ShouldProcess($managedSchema, "Modify")) { |
|
Write-Host " Making Sitecore modifications to schema" |
|
$xmlDoc = [System.Xml.XmlDocument](Get-Content $managedSchemaBackup) |
|
$xmlDoc.schema.uniqueKey = "_uniqueid" |
|
|
|
$field = [System.Xml.XmlNode]$xmlDoc.CreateElement("field") |
|
$field.SetAttribute("name", "_uniqueid") |
|
$field.SetAttribute("type", "string") |
|
$field.SetAttribute("indexed", "true") |
|
$field.SetAttribute("required", "true") |
|
$field.SetAttribute("stored", "true") |
|
|
|
$idField = [System.Xml.XmlNode]$xmlDoc.schema.GetElementsByTagName("field")[0] |
|
[void]$xmlDoc.schema.InsertBefore($field, $idField) |
|
|
|
$xmlDoc.Save($managedSchema) |
|
} |
|
|
|
Write-Host "Done." |
|
} |
|
|
|
Write-Host "Starting SOLR service ($($solrService.Name))" |
|
Start-Service $solrService.Name |
|
} |
|
End { |
|
$ErrorActionPreference = $_eap |
|
} |