Skip to content

Commit 9b5bdd8

Browse files
committed
fix(schema): only advance extension status
Prevent schema extension updates from attempting invalid status rollbacks by applying status changes only when moving forward in Graph’s lifecycle (InDevelopment -> Available -> Deprecated). Also refresh the schema from Graph after PATCH so subsequent persistence uses the latest values.
1 parent b183e48 commit 9b5bdd8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Modules/CIPPCore/Public/Get-CIPPSchemaExtensions.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ function Get-CIPPSchemaExtensions {
88
# Get definitions file
99
$SchemaDefinitionsPath = Join-Path $env:CIPPRootPath 'Config\schemaDefinitions.json'
1010

11+
# Graph only allows the status to move forward through this lifecycle
12+
$StatusOrder = @{ InDevelopment = 0; Available = 1; Deprecated = 2 }
13+
1114
# check CustomData table for schema extensions
1215
$CustomDataTable = Get-CippTable -tablename 'CustomData'
1316
try {
@@ -47,7 +50,7 @@ function Get-CIPPSchemaExtensions {
4750
if (Compare-Object -ReferenceObject ($SchemaDefinition.properties | Sort-Object name | Select-Object name, type) -DifferenceObject ($Schema.properties | Sort-Object name | Select-Object name, type)) {
4851
$Patch.properties = $SchemaDefinition.properties
4952
}
50-
if ($Schema.status -ne $SchemaDefinition.status) {
53+
if ($StatusOrder[$SchemaDefinition.status] -gt $StatusOrder[$Schema.status]) {
5154
$Patch.status = $SchemaDefinition.status
5255
}
5356
if ($Schema.targetTypes -ne $SchemaDefinition.targetTypes) {
@@ -84,6 +87,7 @@ function Get-CIPPSchemaExtensions {
8487
}
8588
$PatchJson = ConvertTo-Json -Depth 5 -InputObject $Patch
8689
$null = New-GraphPOSTRequest -type PATCH -Uri "https://graph.microsoft.com/v1.0/schemaExtensions/$($Schema.id)" -Body $PatchJson -AsApp $true -NoAuthCheck $true
90+
$Schema = New-GraphGETRequest -uri "https://graph.microsoft.com/v1.0/schemaExtensions/$($Schema.id)" -AsApp $true -NoAuthCheck $true
8791
}
8892
try {
8993
$OldSchema = $SchemaExtensions | Where-Object { $Schema.id -match $_.RowKey }

0 commit comments

Comments
 (0)