Füge neues Skript für MegaMenu Site-Scope-Test hinzu, um die Konfiguration zu überprüfen und Site-Actions zu verwalten
This commit is contained in:
126
deployment/test-megamenu-site-scope.ps1
Normal file
126
deployment/test-megamenu-site-scope.ps1
Normal file
@@ -0,0 +1,126 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$SiteUrl,
|
||||
|
||||
[string]$Description = 'MSFT-Custom-Solution:MegaMenu'
|
||||
)
|
||||
|
||||
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
$componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506'
|
||||
$legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b'
|
||||
$location = 'ClientSideExtension.ApplicationCustomizer'
|
||||
$configurationProperty = 'PortalSettings.MegaMenu.Configuration'
|
||||
|
||||
$site = Get-SPSite -Identity $SiteUrl
|
||||
|
||||
try {
|
||||
$rootWeb = $site.RootWeb
|
||||
$properties = [string]$rootWeb.AllProperties[$configurationProperty]
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($properties)) {
|
||||
$existingAction = $null
|
||||
|
||||
foreach ($web in $site.AllWebs) {
|
||||
try {
|
||||
$existingAction = @(
|
||||
$web.UserCustomActions |
|
||||
Where-Object {
|
||||
$_.ClientSideComponentId -eq $componentId -or
|
||||
$_.ClientSideComponentId -eq $legacyComponentId
|
||||
}
|
||||
) | Select-Object -First 1
|
||||
|
||||
if ($existingAction) {
|
||||
$properties = [string]$existingAction.ClientSideComponentProperties
|
||||
break
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$web.Dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($properties)) {
|
||||
throw ('Keine MegaMenu-Konfiguration im Property Bag oder in einer bestehenden ' +
|
||||
'Web-Registrierung gefunden. Bitte zuerst add-megamenu.ps1 ausfuehren.')
|
||||
}
|
||||
|
||||
try {
|
||||
$null = $properties | ConvertFrom-Json
|
||||
}
|
||||
catch {
|
||||
throw ('Die gefundene MegaMenu-Konfiguration ist kein gueltiges JSON: ' + $_.Exception.Message)
|
||||
}
|
||||
|
||||
$removedSiteActions = 0
|
||||
@(
|
||||
$site.UserCustomActions |
|
||||
Where-Object {
|
||||
$_.ClientSideComponentId -eq $componentId -or
|
||||
$_.ClientSideComponentId -eq $legacyComponentId
|
||||
}
|
||||
) | ForEach-Object {
|
||||
$_.Delete()
|
||||
$removedSiteActions++
|
||||
}
|
||||
|
||||
$siteAction = $site.UserCustomActions.Add()
|
||||
$siteAction.Name = [Guid]::NewGuid().ToString('B')
|
||||
$siteAction.Title = 'MegaMenu Application Customizer'
|
||||
$siteAction.Description = $Description
|
||||
$siteAction.Location = $location
|
||||
$siteAction.ClientSideComponentId = $componentId
|
||||
$siteAction.ClientSideComponentProperties = $properties
|
||||
$siteAction.Sequence = 100
|
||||
$siteAction.Update()
|
||||
|
||||
$removedWebActions = 0
|
||||
$testedWebUrls = @()
|
||||
|
||||
foreach ($web in $site.AllWebs) {
|
||||
try {
|
||||
$testedWebUrls += $web.Url
|
||||
|
||||
@(
|
||||
$web.UserCustomActions |
|
||||
Where-Object {
|
||||
$_.ClientSideComponentId -eq $componentId -or
|
||||
$_.ClientSideComponentId -eq $legacyComponentId
|
||||
}
|
||||
) | ForEach-Object {
|
||||
$_.Delete()
|
||||
$removedWebActions++
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$web.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
$verification = @(
|
||||
$site.UserCustomActions |
|
||||
Where-Object { $_.ClientSideComponentId -eq $componentId }
|
||||
)
|
||||
|
||||
Write-Host ''
|
||||
Write-Host '=== MegaMenu Site-Scope-Test vorbereitet ===' -ForegroundColor Green
|
||||
Write-Host ('Site-Action-ID: ' + $siteAction.Id)
|
||||
Write-Host ('Component-ID: ' + $componentId)
|
||||
Write-Host ('Entfernte vorherige Site-Actions: ' + $removedSiteActions)
|
||||
Write-Host ('Entfernte Web-Actions: ' + $removedWebActions)
|
||||
Write-Host ('Verifizierte Site-Actions: ' + $verification.Count)
|
||||
Write-Host ('Properties: ' + $properties)
|
||||
Write-Host ''
|
||||
Write-Host 'Bitte jeweils mit Strg+F5 testen:' -ForegroundColor Cyan
|
||||
$testedWebUrls | ForEach-Object { Write-Host (' ' + $_) }
|
||||
Write-Host ''
|
||||
Write-Host 'Rueckkehr zum bisherigen Web-Scope:' -ForegroundColor Yellow
|
||||
Write-Host ('.\deployment\add-megamenu.ps1 -SiteUrl ''' + $site.Url + '''')
|
||||
}
|
||||
finally {
|
||||
if ($site) {
|
||||
$site.Dispose()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user