Skip to content

Commit 951f831

Browse files
committed
fix(sherweb): stop migration tasks from running after extension disable
Two defects allowed Invoke-SherwebMigration scheduled tasks to keep firing daily (sending alerts and performing real Sherweb purchases and Pax8 subscription cancellations) after the Sherweb migration was disabled: - Invoke-SherwebMigration had no enabled-guard: it read the Sherweb extension config but never checked Enabled before acting. It now returns immediately unless the Sherweb config exists and Enabled is true, which neutralizes any stale scheduled task. - Register-CIPPExtensionScheduledTasks created migration tasks in the enable branch, but the disable cleanup only filtered Push-CippExtensionData tasks, so migration tasks were never removed. Migration tasks are now queried at function scope, removed when the Sherweb extension is disabled, and removed when a tenant is no longer Sherweb-mapped.
1 parent 784cff5 commit 951f831

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

Modules/CippExtensions/Public/Extension Functions/Register-CippExtensionScheduledTasks.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function Register-CIPPExtensionScheduledTasks {
1414
$ScheduledTasksTable = Get-CIPPTable -TableName ScheduledTasks
1515
$ScheduledTasks = Get-CIPPAzDataTableEntity @ScheduledTasksTable -Filter 'Hidden eq true' | Where-Object { $_.Command -match 'Sync-CippExtensionData' }
1616
$PushTasks = Get-CIPPAzDataTableEntity @ScheduledTasksTable -Filter 'Hidden eq true' | Where-Object { $_.Command -match 'Push-CippExtensionData' }
17+
$SherwebMigTasks = Get-CIPPAzDataTableEntity @ScheduledTasksTable -Filter 'Hidden eq true' | Where-Object { $_.Command -match 'Invoke-SherwebMigration' }
1718
$Tenants = Get-Tenants -IncludeErrors
1819

1920
# Remove all legacy Sync-CippExtensionData tasks (now deprecated - extensions use CippReportingDB)
@@ -32,7 +33,6 @@ function Register-CIPPExtensionScheduledTasks {
3233
if ($Extension -eq 'Sherweb') {
3334
# Sherweb migration tasks - schedule per mapped tenant
3435
$SherwebMappings = Get-CIPPAzDataTableEntity @MappingsTable -Filter "PartitionKey eq 'SherwebMapping'"
35-
$SherwebMigTasks = Get-CIPPAzDataTableEntity @ScheduledTasksTable -Filter 'Hidden eq true' | Where-Object { $_.Command -match 'Invoke-SherwebMigration' }
3636
foreach ($Mapping in $SherwebMappings) {
3737
$Tenant = $Tenants | Where-Object { $_.customerId -eq $Mapping.RowKey }
3838
if (-not $Tenant) { continue }
@@ -145,6 +145,14 @@ function Register-CIPPExtensionScheduledTasks {
145145
$Entity = $_ | Select-Object -Property PartitionKey, RowKey
146146
Remove-AzDataTableEntity -Force @ScheduledTasksTable -Entity $Entity
147147
}
148+
if ($Extension -eq 'Sherweb') {
149+
$SherwebMigTasks | ForEach-Object {
150+
Write-Information "Extension Disabled: Cleaning up scheduled task $($_.Name) for tenant $($_.Tenant)"
151+
$Entity = $_ | Select-Object -Property PartitionKey, RowKey
152+
Remove-AzDataTableEntity -Force @ScheduledTasksTable -Entity $Entity
153+
}
154+
$SherwebMigTasks = @() # Clear the list since we removed them all
155+
}
148156
}
149157
}
150158
$MappedTenants = $MappedTenants | Sort-Object -Unique
@@ -163,4 +171,11 @@ function Register-CIPPExtensionScheduledTasks {
163171
Remove-AzDataTableEntity -Force @ScheduledTasksTable -Entity $Entity
164172
}
165173
}
174+
foreach ($Task in $SherwebMigTasks) {
175+
if ($Task.Tenant -notin $MappedTenants) {
176+
Write-Information "Tenant Removed: Cleaning up scheduled task $($Task.Name) for tenant $($Task.TenantFilter)"
177+
$Entity = $Task | Select-Object -Property PartitionKey, RowKey
178+
Remove-AzDataTableEntity -Force @ScheduledTasksTable -Entity $Entity
179+
}
180+
}
166181
}

Modules/CippExtensions/Public/Sherweb/Invoke-SherwebMigration.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ function Invoke-SherwebMigration {
88
$ExtensionConfig = (Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json
99
$Config = $ExtensionConfig.Sherweb
1010

11+
if ($Config.Enabled -ne $true) {
12+
Write-Information "Sherweb extension is disabled, skipping migration check for $TenantFilter"
13+
return
14+
}
15+
1116
# Get licenses within the transfer window (renewing within 7 days)
1217
$Licenses = Get-CIPPLicenseOverview -TenantFilter $TenantFilter | Where-Object {
1318
$null -ne $_.TermInfo -and ($_.TermInfo | Where-Object { $_.DaysUntilRenew -le 7 -and $_.DaysUntilRenew -ge 0 })

0 commit comments

Comments
 (0)