Skip to content

Commit f5489de

Browse files
committed
Improve template update logic and compress JSON output
Update template update checks to ensure the source matches the current template repository before updating or skipping. Also, add the -Compress flag to ConvertTo-Json calls to reduce JSON size when storing entities.
1 parent bfe9a6f commit f5489de

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Modules/CIPPCore/Public/New-CIPPTemplateRun.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ function New-CIPPTemplateRun {
5252
$ExistingTemplate = $ExistingTemplates | Where-Object { (![string]::IsNullOrEmpty($_.displayName) -and (Get-SanitizedFilename -filename $_.displayName) -eq (Get-SanitizedFilename -filename $File.name)) -or (![string]::IsNullOrEmpty($_.templateName) -and (Get-SanitizedFilename -filename $_.templateName) -eq (Get-SanitizedFilename -filename $File.name) ) -and ![string]::IsNullOrEmpty($_.SHA) } | Select-Object -First 1
5353

5454
$UpdateNeeded = $false
55-
if ($ExistingTemplate -and $ExistingTemplate.SHA -ne $File.sha) {
55+
if ($ExistingTemplate -and $ExistingTemplate.SHA -ne $File.sha -and $ExistingTemplate.Source -eq $TemplateSettings.templateRepo.value) {
5656
$Name = $ExistingTemplate.displayName ?? $ExistingTemplate.templateName
5757
Write-Information "Existing template $($Name) found, but SHA is different. Updating template."
5858
$UpdateNeeded = $true
5959
"Template $($Name) needs to be updated as the SHA is different"
60-
} elseif ($ExistingTemplate -and $ExistingTemplate.SHA -eq $File.sha) {
60+
} elseif ($ExistingTemplate -and $ExistingTemplate.SHA -eq $File.sha -and $ExistingTemplate.Source -eq $TemplateSettings.templateRepo.value) {
6161
Write-Information "Existing template $($File.name) found, but SHA is the same. No update needed."
6262
"Template $($File.name) found, but SHA is the same. No update needed."
6363
}
@@ -263,7 +263,7 @@ function New-CIPPTemplateRun {
263263
RAWJson = $Template.TemplateJson
264264
Type = $Template.Type
265265
GUID = $ExistingPolicy.GUID
266-
} | ConvertTo-Json
266+
} | ConvertTo-Json -Compress
267267

268268
Add-CIPPAzDataTableEntity @Table -Entity @{
269269
JSON = "$object"
@@ -283,7 +283,7 @@ function New-CIPPTemplateRun {
283283
RAWJson = $Template.TemplateJson
284284
Type = $Template.Type
285285
GUID = $GUID
286-
} | ConvertTo-Json
286+
} | ConvertTo-Json -Compress
287287

288288
Add-CIPPAzDataTableEntity @Table -Entity @{
289289
JSON = "$object"
@@ -317,7 +317,7 @@ function New-CIPPTemplateRun {
317317
RAWJson = $Template.TemplateJson
318318
Type = $Template.Type
319319
GUID = $ExistingPolicy.GUID
320-
} | ConvertTo-Json
320+
} | ConvertTo-Json -Compress
321321

322322
Add-CIPPAzDataTableEntity @Table -Entity @{
323323
JSON = "$object"
@@ -337,7 +337,7 @@ function New-CIPPTemplateRun {
337337
RAWJson = $Template.TemplateJson
338338
Type = $Template.Type
339339
GUID = $GUID
340-
} | ConvertTo-Json
340+
} | ConvertTo-Json -Compress
341341

342342
Add-CIPPAzDataTableEntity @Table -Entity @{
343343
JSON = "$object"

0 commit comments

Comments
 (0)