feat: update to version 2.1.0 with central site collection configuration and inheritance support

This commit is contained in:
Torsten Brendgen
2026-07-18 20:42:00 +02:00
parent 0d6da3451d
commit 0b8b752837
17 changed files with 348 additions and 43 deletions

View File

@@ -24,10 +24,14 @@ $context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
try {
$list = $context.Web.Lists.GetByTitle($ListTitle)
$field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName)
$rootWeb = $context.Site.RootWeb
$customActions = $list.UserCustomActions
$webCustomActions = $context.Web.UserCustomActions
$context.Load($list)
$context.Load($field)
$context.Load($context.Web)
$context.Load($rootWeb)
$context.Load($rootWeb.AllProperties)
$context.Load($customActions)
$context.Load($webCustomActions)
$context.ExecuteQuery()
@@ -41,6 +45,28 @@ try {
$field.ClientSideComponentProperties = ''
$field.Update()
$bindingsKey = 'PortalSettings.ExpiryIndicator.Bindings'
$bindings = @()
$existingBindingsJson = [string]$rootWeb.AllProperties[$bindingsKey]
if (-not [string]::IsNullOrWhiteSpace($existingBindingsJson)) {
try {
$bindings = @($existingBindingsJson | ConvertFrom-Json)
}
catch {
$bindings = @()
}
}
$webUrl = $context.Web.Url.TrimEnd('/')
$listId = $list.Id.ToString('D')
$bindings = @($bindings | Where-Object {
-not (
([string]$_.webUrl).TrimEnd('/').Equals($webUrl, [StringComparison]::OrdinalIgnoreCase) -and
([string]$_.listId).Equals($listId, [StringComparison]::OrdinalIgnoreCase)
)
})
$rootWeb.AllProperties[$bindingsKey] = (ConvertTo-Json -InputObject @($bindings) -Compress -Depth 5)
$rootWeb.Update()
$customActions | Where-Object {
$_.Name -eq 'ExpiryIndicator.Classic.ScriptLink' -or
$_.Name -eq 'ExpiryIndicator.Classic.Ribbon'

View File

@@ -26,10 +26,14 @@ $context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
try {
$list = $context.Web.Lists.GetByTitle($ListTitle)
$field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName)
$rootWeb = $context.Site.RootWeb
$customActions = $list.UserCustomActions
$webCustomActions = $context.Web.UserCustomActions
$context.Load($list)
$context.Load($field)
$context.Load($context.Web)
$context.Load($rootWeb)
$context.Load($rootWeb.AllProperties)
$context.Load($customActions)
$context.Load($webCustomActions)
$context.ExecuteQuery()
@@ -41,12 +45,58 @@ try {
$alreadyBound = $field.ClientSideComponentId -eq $FieldCustomizerComponentId
$field.ClientSideComponentId = $FieldCustomizerComponentId
if (-not $alreadyBound -or [string]::IsNullOrWhiteSpace($field.ClientSideComponentProperties)) {
$field.ClientSideComponentProperties = (@{
$field.ClientSideComponentProperties = ([ordered]@{
schemaVersion = 2
expiryField = $field.InternalName
inheritSiteDefaults = $true
} | ConvertTo-Json -Compress)
}
$field.Update()
$descriptorKey = 'PortalSettings.Solutions.ExpiryIndicator'
$bindingsKey = 'PortalSettings.ExpiryIndicator.Bindings'
$rootWeb.AllProperties[$descriptorKey] = ([ordered]@{
key = 'ExpiryIndicator'
displayName = 'Expiry Indicator'
version = '2.1.0'
provider = 'expiryIndicator'
componentIds = @(
'a555f4fc-d6a6-4421-8189-457449d9bbde',
'cd58f5d9-ffc8-4df7-a910-3054842d7abf',
'95691218-bcb1-4fad-adda-02bb12014d15'
)
settingsScope = @('siteCollection', 'web', 'list')
} | ConvertTo-Json -Compress -Depth 5)
$bindings = @()
$existingBindingsJson = [string]$rootWeb.AllProperties[$bindingsKey]
if (-not [string]::IsNullOrWhiteSpace($existingBindingsJson)) {
try {
$bindings = @($existingBindingsJson | ConvertFrom-Json)
}
catch {
Write-Warning 'Das vorhandene ExpiryIndicator-Bindungsinventar war ungültig und wird neu aufgebaut.'
}
}
$webUrl = $context.Web.Url.TrimEnd('/')
$listId = $list.Id.ToString('D')
$bindings = @($bindings | Where-Object {
-not (
([string]$_.webUrl).TrimEnd('/').Equals($webUrl, [StringComparison]::OrdinalIgnoreCase) -and
([string]$_.listId).Equals($listId, [StringComparison]::OrdinalIgnoreCase)
)
})
$bindings += [ordered]@{
webUrl = $webUrl
listId = $listId
listTitle = $list.Title
fieldInternalName = $field.InternalName
fieldId = $field.Id.ToString('D')
}
$rootWeb.AllProperties[$bindingsKey] = (ConvertTo-Json -InputObject @($bindings) -Compress -Depth 5)
$rootWeb.Update()
# Remove old diagnostic registrations and make the V2 Classic
# registrations idempotent.
$customActions | Where-Object {