Bump version to 2.0.0, update component ID, and enhance central configuration for MegaMenu

This commit is contained in:
Torsten Brendgen
2026-07-19 23:15:38 +02:00
parent 07583b8122
commit 85c56a1153
11 changed files with 102 additions and 86 deletions

View File

@@ -17,90 +17,99 @@ param(
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
$componentId = 'abc3361f-bb2d-491f-aba3-cd51c19a299b'
$componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506'
$legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b'
$location = 'ClientSideExtension.ApplicationCustomizer'
$name = 'MegaMenu'
$title = 'Mega Menu'
$configurationProperty = 'PortalSettings.MegaMenu.Configuration'
function Get-MegaMenuPropertiesJson {
param(
[string]$CurrentTermSetName,
[string]$CurrentTermSetId,
[int]$CurrentCacheMinutes,
[bool]$CurrentDebug
$properties = @{
termSetName = $TermSetName
termSetId = $TermSetId
cacheMinutes = $CacheMinutes
debug = [bool]$EnableDebug.IsPresent
} | ConvertTo-Json -Depth 10 -Compress
$site = Get-SPSite -Identity $SiteUrl
try {
$rootWeb = $site.RootWeb
$rootWeb.AllProperties[$configurationProperty] = $properties
$rootWeb.Update()
$siteActions = @(
$site.UserCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
)
return (@{
termSetName = $CurrentTermSetName
termSetId = $CurrentTermSetId
cacheMinutes = $CurrentCacheMinutes
debug = $CurrentDebug
} | ConvertTo-Json -Depth 10 -Compress)
}
foreach ($siteAction in $siteActions) {
$siteAction.Delete()
}
function Remove-WebScopedComponentActions {
param(
[Microsoft.SharePoint.SPSite]$CurrentSite,
[string]$CurrentComponentId,
[string]$CurrentLocation
)
$created = 0
$updated = 0
$removedLegacy = 0
$removedCount = 0
foreach ($web in $CurrentSite.AllWebs) {
foreach ($web in $site.AllWebs) {
try {
$webActions = @($web.UserCustomActions | Where-Object {
$_.Location -eq $CurrentLocation -and
$_.ClientSideComponentId -and
$_.ClientSideComponentId.ToString().ToLower() -eq $CurrentComponentId
})
$actions = @(
$web.UserCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
)
foreach ($webAction in $webActions) {
$web.UserCustomActions.Delete($webAction.Id)
$removedCount++
$currentAction = $actions |
Where-Object {
$_.ClientSideComponentId -eq $componentId
} |
Select-Object -First 1
foreach ($existingAction in $actions) {
if ($currentAction -and $existingAction.Id -eq $currentAction.Id) {
continue
}
$existingAction.Delete()
$removedLegacy++
}
if ($webActions.Count -gt 0) {
$web.Update()
if (-not $currentAction) {
$currentAction = $web.UserCustomActions.Add()
$currentAction.Name = [Guid]::NewGuid().ToString('B')
$created++
}
else {
$updated++
}
$currentAction.Title = 'MegaMenu Application Customizer'
$currentAction.Description = $Description
$currentAction.Location = $location
$currentAction.ClientSideComponentId = $componentId
$currentAction.ClientSideComponentProperties = $properties
$currentAction.Sequence = 100
$currentAction.Update()
$web.Update()
Write-Host ('MegaMenu synchronisiert: ' + $web.Url) -ForegroundColor Green
}
finally {
$web.Dispose()
}
}
return $removedCount
}
$site = Get-SPSite -Identity $SiteUrl
try {
$removedWebScopedActions = Remove-WebScopedComponentActions -CurrentSite $site -CurrentComponentId $componentId -CurrentLocation $location
$existingAction = $site.UserCustomActions | Where-Object {
$_.Location -eq $location -and $_.ClientSideComponentId -and $_.ClientSideComponentId.ToString().ToLower() -eq $componentId
} | Select-Object -First 1
if ($existingAction) {
$action = $existingAction
Write-Host 'Aktualisiere vorhandene site-scoped Mega Menu UserCustomAction...' -ForegroundColor Yellow
}
else {
$action = $site.UserCustomActions.Add()
Write-Host 'Erstelle neue site-scoped Mega Menu UserCustomAction...' -ForegroundColor Yellow
}
$action.Name = $name
$action.Title = $title
$action.Description = $Description
$action.Location = $location
$action.ClientSideComponentId = [Guid]$componentId
$action.ClientSideComponentProperties = Get-MegaMenuPropertiesJson -CurrentTermSetName $TermSetName -CurrentTermSetId $TermSetId -CurrentCacheMinutes $CacheMinutes -CurrentDebug ([bool]$EnableDebug.IsPresent)
$action.Update()
Write-Host 'Mega Menu wurde site-scoped registriert.' -ForegroundColor Green
Write-Host ('Entfernte web-scoped Eintraege: ' + $removedWebScopedActions)
Write-Host ('Beschreibung: ' + $Description)
Write-Host ('Properties: ' + $action.ClientSideComponentProperties)
Write-Host ''
Write-Host 'MegaMenu wurde fuer die gesamte Site Collection konfiguriert.' -ForegroundColor Green
Write-Host ('Zentrale Konfiguration: ' + $configurationProperty)
Write-Host ('Neu registrierte Webs: ' + $created)
Write-Host ('Aktualisierte Webs: ' + $updated)
Write-Host ('Entfernte alte oder doppelte Registrierungen: ' + $removedLegacy)
Write-Host ('Properties: ' + $properties)
Write-Host 'Neue Unterwebs koennen durch erneutes Ausfuehren idempotent synchronisiert werden.' -ForegroundColor Yellow
}
finally {
if ($site) {