Pipelines/Steps/Install/OnPrem/Solr/Add-SolrCoresEnvConfig.ps1

$ErrorActionPreference = "Stop"

Write-Output "Add Solr cores environment config (if needed) started..."

if ((($null -eq $SAFConfiguration.search.solr.rebuildCores) -or ($SAFConfiguration.search.solr.rebuildCores.Count -lt 1)) -and (($null -eq $SAFConfiguration.search.solr.customCores) -or ($SAFConfiguration.search.solr.customCores.Count -lt 1))) {
    Write-Output "No custom or rebuild cores defined. Skipping..."
}
else {
    $cores = @()

    foreach ($rebuildCore in $SAFConfiguration.search.solr.rebuildCores) {
        $cores += [PSCustomObject]@{    
            indexName = "sitecore_$($rebuildCore)"
            mainName  = "$($SAFConfiguration.prefix)_$($rebuildCore)"
            rebuild = $true
        }
    }

    foreach ($customCore in $SAFConfiguration.search.solr.customCores) {
        $alreadyAdded = $false
        foreach ($rebuildCore in $SAFConfiguration.search.solr.rebuildCores) {
            if($customCore -eq $rebuildCore){
                $alreadyAdded = $true
            }
        }

        if($alreadyAdded){
            continue
        }

        $cores += [PSCustomObject]@{    
            indexName = "sitecore_$($customCore)"
            mainName  = "$($SAFConfiguration.prefix)_$($customCore)"
            rebuild = $false
        }
    }
    
    $sitecoreDir = $SAFConfiguration.sitecore.installDir
    AddSolrCoresConfig -SitecoreDir "$sitecoreDir" -Cores $cores
}

Write-Output "Add Solr cores environment config (if needed) done."