diff --git a/Doc/ReleaseNotes-ISHRemote-8.3.md b/Doc/ReleaseNotes-ISHRemote-8.3.md index 71ff3fa..3e37bb3 100644 --- a/Doc/ReleaseNotes-ISHRemote-8.3.md +++ b/Doc/ReleaseNotes-ISHRemote-8.3.md @@ -36,6 +36,33 @@ Set-IshDocumentObj -Metadata (Set-IshMetadataField -Name "FSTATUS" -Level Lng -V ``` +### Archive and Remove released publication outputs +Removing unwanted publication outputs is one way to shrink a large environment. Released publication outputs are secured by the server, so `Remove-IshPublicationOutput` got a new `-Unrelease` switch which first sets the status of a released output to Draft and then removes it. Publication Outputs that are currently publishing are skipped with a warning, re-run once publishing completes. Requires 14SP4/14.0.4 with hotfix CRQ-31475, or 15/15.0.0 and up. The publication logical and version cards survive unless you also add `-Force`. + +For example, first with `-WhatIf`, then remove the switch: +```powershell +Get-IshFolder -FolderPath "General\MyPublications" -FolderTypeFilter @("ISHPublication") -Recurse | +ForEach-Object -Process { + Get-IshFolderContent -IshFolder $_ -VersionFilter "" | + Remove-IshPublicationOutput -Unrelease -WhatIf +} +``` +To archive instead, download the rendered data of one folder at a time before removing it: +```powershell + $metadataFilter = Set-IshMetadataFilterField -Name "FISHLASTMODIFIEDON" -Level Lng -ValueType Value -FilterOperator LessThan -Value "01/01/2022 00:00:00" +Get-IshFolder -FolderPath "General\MyPublications" -FolderTypeFilter @("ISHPublication") -Recurse | +ForEach-Object -Process { + Get-IshFolderContent -IshFolder $_ -VersionFilter "" -MetadataFilter $metadataFilter | + Tee-Object -Variable publicationOutputs | + Get-IshPublicationOutputData -FolderPath "C:\Temp\Archive" + $publicationOutputs | Remove-IshPublicationOutput -Unrelease -WhatIf +} +``` +Note that `Get-IshPublicationOutputData` only downloads outputs that have rendered data, so draft-only outputs silently produce no file. + +Note that we now marked for deletion, just like you would do in Organize Space or Client tools. The Crawler service does the actual delete. And a database shrink by your database engine finally returns the space. See the [community thread](https://community.rws.com/product-groups/tridion/tridion-docs/f/forum/61643/shrinking-a-large-test-database-can-you-create-a-new-db-with-all-the-existing-metadata-but-no-data) for background. + + ## Platform Support for PowerShell .... @@ -51,6 +78,7 @@ Set-IshDocumentObj -Metadata (Set-IshMetadataField -Name "FSTATUS" -Level Lng -V * Fixed cmdlets over protocol `WcfSoapWithOpenIdConnect` occasionally throwing `An unsecured or incorrectly secured fault was received from the other party` on the first SOAP call after a channel fault, requiring the user to re-run the same cmdlet for it to succeed (the existing #201/#219 rebuild-on-next-call logic only kicked in on a second, separate call). Each `Get*25Channel()` method in `InfoShareWcfSoapWithOpenIdConnectConnection` now returns the channel wrapped in a new `RetryOnFaultProxy` (`System.Reflection.DispatchProxy`) that catches `CommunicationException`/`FaultException` on the actual SOAP call, rebuilds the channel via the existing rebuild logic, and retries exactly once within the same cmdlet invocation before propagating any further failure — with the original exception type/stack trace preserved. Requires a new `net48`-only NuGet dependency, `System.Reflection.DispatchProxy` (built into the BCL on `net6.0`/`net10.0`). See #273. Thanks @ddemeyer * Extended `New-IshSession` with an automatic `User-Agent` fallback on PowerShell 7+ so it no longer gets blocked outright by cloud WAF bot-management rule groups (AWS WAF Bot Control, Azure Front Door/App Gateway WAF bot manager rules, GCP Cloud Armor adaptive protection/bot management) that inspect the `User-Agent` header on every request. Measured behavior against a live WAF-fronted environment: sending no `User-Agent` at all (today's default) or a bare `Product/Version` token (e.g. `ISHRemote/8.3.0`) both get bucketed with known non-browser tooling (`curl`, `python-requests`, ...) and blocked with `HTTP 403 Forbidden`. When WAF blocks the connection on the first `403` from the `connectionconfiguration.xml` probe, `New-IshSession` retries once with `Mozilla/5.0 (compatible; ISHRemote/{version}; +https://github.com/rws/ISHRemote)`; on success that header sticks for the session's lifetime and every subsequent request carries it. Windows PowerShell 5.1 (`net48`) will warn instead of a raw WCF exception, recommending you to ask your Tridion Docs administrator to adjust the WAF bot-management rule for this endpoint, or switch to PowerShell 7+ where the fallback is applied automatically. See #275. Thanks @ddemeyer * Enhanced `New-IshSession` and `Test-IshSession` protocol `Autodetect` (the default) to select `OpenApiWithOpenIdConnect` on Tridion Docs 15/15.0.0 and later, instead of `WcfSoapWithOpenIdConnect` on earlier ISHRemote versions. Cmdlets already choose between OpenAPI and SOAP per call, so `WcfSoapWithOpenIdConnect` remains the per-cmdlet fallback. An explicit `-Protocol`, including `WcfSoapWithOpenIdConnect`, works as before. See #282. Thanks @ddemeyer +* Extended `Remove-IshPublicationOutput` with switch `-Unrelease` which sets released publication outputs to Draft before removing them, skipping outputs that are currently publishing with a warning. Supersedes #262. See #268. Thanks @ddemeyer * Package bumps, deliberate adding of `System.Security.Cryptography.Xml` to fix vulnerability coming from transitive `System.ServiceModel.Primitives`. See #278 and #279. Thanks @ddemeyer diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 index c1beccd..d65196d 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 @@ -65,6 +65,37 @@ Describe "Remove-IshPublicationOutput" -Tags "Delete" { $publicationOutput.length -eq 0 | Should-Be $true } } + + Context "Remove-IshPublicationOutput -Unrelease" { + # Full coverage of unreleasing starting from VPUBSTATUSRELEASED needs a prior publish cycle (Publishing to Released), which is manual-tested. + # These tests cover the draft status path where -Unrelease must leave the output alone and simply remove it. + It "-Unrelease on draft output removed over IshObject pipeline" { + $ishPubMetadata = $ishPublicationOutputMetadata | Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Pub $cmdletName Unrelease $timestamp" + $ishPub = Add-IshPublicationOutput -IshSession $ishSession -IshFolder $ishFolderPub -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Metadata $ishPubMetadata + $ishPub | Remove-IshPublicationOutput -IshSession $ishSession -Unrelease -Force + $publicationOutput = Get-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef + $publicationOutput.length -eq 0 | Should-Be $true + } + It "-Unrelease on draft output removed over ParameterGroup" { + $ishPubMetadata = $ishPublicationOutputMetadata | Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Pub $cmdletName Unrelease $timestamp" + $ishPub = Add-IshPublicationOutput -IshSession $ishSession -IshFolder $ishFolderPub -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Metadata $ishPubMetadata + Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef -Version $ishPub.version_version_value -LanguageCombination $ishPub.fishpublngcombination -OutputFormat $ishPub.fishoutputformatref_lng_element -Unrelease -Force + $publicationOutput = Get-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef + $publicationOutput.length -eq 0 | Should-Be $true + } + It "-Unrelease with -Force cascades to version and logical on last language" { + $ishPubMetadata = $ishPublicationOutputMetadata | Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Pub $cmdletName Unrelease $timestamp" + $ishPub = Add-IshPublicationOutput -IshSession $ishSession -IshFolder $ishFolderPub -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Metadata $ishPubMetadata + # -WhatIf should not remove the publication output + $ishPub | Remove-IshPublicationOutput -IshSession $ishSession -Unrelease -Force -WhatIf + $publicationOutput = Get-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef + $publicationOutput.length -eq 1 | Should-Be $true + # -Force should remove the publication output + $ishPub | Remove-IshPublicationOutput -IshSession $ishSession -Unrelease -Force + $publicationOutput = Get-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef + $publicationOutput.length -eq 0 | Should-Be $true + } + } } AfterAll { @@ -73,4 +104,3 @@ AfterAll { try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshPublicationOutput -IshSession $ishSession -Force } catch { Write-Host "An error occurred: $_" } try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { Write-Host "An error occurred: $_" } } - diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs index 095decc..5ccc78b 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs @@ -43,6 +43,31 @@ namespace Trisoft.ISHRemote.Cmdlets.PublicationOutput /// /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Removing a publication output /// + /// + /// + /// $metadataFilter = Set-IshMetadataFilterField -Name "FISHLASTMODIFIEDON" -Level Lng -ValueType Value -FilterOperator LessThan -Value "01/01/2022 00:00:00" + /// Get-IshFolder -FolderPath "General\MyPublications" -FolderTypeFilter @("ISHPublication") -Recurse | + /// ForEach-Object -Process { + /// Get-IshFolderContent -IshFolder $_ -VersionFilter "" -MetadataFilter $metadataFilter | + /// Remove-IshPublicationOutput -Unrelease -WhatIf + /// } + /// + /// Walks the publication folders and, for the publication outputs not modified since 2022, describes (-WhatIf) the unrelease of released outputs followed by their removal. Remove -WhatIf to commit. The publication version and logical cards survive because -Force is not used. + /// + /// + /// + /// $metadataFilter = Set-IshMetadataFilterField -Name FISHLASTMODIFIEDON -Level Lng -ValueType Value -FilterOperator LessThan -Value "01/01/2022 00:00:00" | + /// Set-IshMetadataFilterField -Name FISHPUBSTATUS -Level Lng -ValueType Element -FilterOperator Equal -Value VPUBSTATUSRELEASED + /// Get-IshFolder -FolderPath "General\MyPublications" -FolderTypeFilter @("ISHPublication") -Recurse | + /// ForEach-Object -Process { + /// Get-IshFolderContent -IshFolder $_ -VersionFilter "" -MetadataFilter $metadataFilter | + /// Tee-Object -Variable publicationOutputs | + /// Get-IshPublicationOutputData -FolderPath "C:\Temp\Archive" + /// $publicationOutputs | Remove-IshPublicationOutput -Unrelease + /// } + /// + /// Archiving pattern that downloads the rendered data of the publication outputs of one folder at a time to the file system, and only then unreleases and removes them. Note that Get-IshPublicationOutputData only downloads outputs that have rendered data, so draft-only outputs silently produce no file. + /// [Cmdlet(VerbsCommon.Remove, "IshPublicationOutput", SupportsShouldProcess = true)] public sealed class RemoveIshPublicationOutput : PublicationOutputCmdlet { @@ -105,15 +130,65 @@ public sealed class RemoveIshPublicationOutput : PublicationOutputCmdlet [ValidateNotNullOrEmpty] public SwitchParameter Force { get; set; } + /// + /// When the Unrelease switch is set, publication outputs with status Released are first unreleased (status set to Draft) so the server accepts their removal. Publication outputs that are currently publishing are skipped with a warning and neither unreleased nor removed. Requires 14SP4/14.0.4 with hotfix CRQ-31475, or 15/15.0.0 and up. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectGroup")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")] + public SwitchParameter Unrelease { get; set; } + protected override void BeginProcessing() { if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); } if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateGlobalIshSession); } if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); } WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession} or in turn SessionState.{ISHRemoteSessionStateGlobalIshSession}"); + if (Unrelease.IsPresent && + ((IshSession.ServerIshVersion.MajorVersion < 14) || ((IshSession.ServerIshVersion.MajorVersion == 14) && (IshSession.ServerIshVersion.RevisionVersion < 4)))) + { + throw new PlatformNotSupportedException($"Remove-IshPublicationOutput with parameter Unrelease requires server-side unrelease of publication outputs which is only available starting from 14SP4/14.0.4 (with hotfix CRQ-31475) and up. ServerIshVersion[{IshSession.ServerVersion}]"); + } base.BeginProcessing(); } + private const string PublicationStatusFieldName = "FISHPUBSTATUS"; + private const string PublishingStatus = "VPUBSTATUSPUBLISHING"; + private const string ReleasedStatus = "VPUBSTATUSRELEASED"; + private const string DraftStatus = "VPUBSTATUSPUBLISHEDDRAFT"; + + private IshFields PublicationStatusRequestedMetadata() + { + var requestedMetadata = new IshFields(); + requestedMetadata.AddField(new IshRequestedMetadataField(PublicationStatusFieldName, Enumerations.Level.Lng, Enumerations.ValueType.Element)); + return requestedMetadata; + } + + private IshFields UnreleaseMetadata() + { + var metadata = new IshFields(); + metadata.AddField(new IshMetadataField(PublicationStatusFieldName, Enumerations.Level.Lng, Enumerations.ValueType.Element, DraftStatus)); + return IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, metadata, Enumerations.ActionMode.Update); + } + + /// + /// Handles the optional unrelease of a publication output right before its removal. + /// + /// False when the publication output is currently publishing and must be skipped + private bool UnreleaseBeforeRemove(string target, string currentStatus, Action unrelease) + { + WriteDebug($"target[{target}] {PublicationStatusFieldName}[{currentStatus}]"); + if (currentStatus == PublishingStatus) + { + WriteWarning($"Skipping target[{target}] because it is currently publishing. Re-run after publishing completes."); + return false; + } + if (currentStatus == ReleasedStatus && ShouldProcess(target + " Unrelease")) + { + unrelease(); + } + return true; + } + /// /// Process the Remove-IshPublicationOutput commandlet. @@ -147,6 +222,21 @@ protected override void ProcessRecord() { long lngRef = Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng]); WriteDebug($"lngRef[{lngRef}] {++current}/{ishObjects.Objects.Length}"); + if (Unrelease.IsPresent) + { + string currentStatus = ishObject.IshFields.GetFieldValue(PublicationStatusFieldName, Enumerations.Level.Lng, Enumerations.ValueType.Element); + if (string.IsNullOrEmpty(currentStatus)) + { + string xmlStatus = IshSession.PublicationOutput25.RetrieveMetadataByIshLngRefs(new long[] { lngRef }, PublicationStatusRequestedMetadata().ToXml()); + var statusObject = new IshObjects(ISHType, xmlStatus).Objects.FirstOrDefault(); + currentStatus = (statusObject == null) ? "" : statusObject.IshFields.GetFieldValue(PublicationStatusFieldName, Enumerations.Level.Lng, Enumerations.ValueType.Element); + } + if (!UnreleaseBeforeRemove(Convert.ToString(lngRef), currentStatus, + () => IshSession.PublicationOutput25.SetMetadataByIshLngRef(lngRef, UnreleaseMetadata().ToXml(), ""))) + { + continue; + } + } if (ShouldProcess(Convert.ToString(lngRef))) { IshSession.PublicationOutput25.DeleteByIshLngRef(lngRef, requiredCurrentMetadata.ToXml()); @@ -158,6 +248,19 @@ protected override void ProcessRecord() } else { + if (Unrelease.IsPresent) + { + var statusResponse = IshSession.PublicationOutput25.GetMetadata(new GetMetadataRequest( + LogicalId, Version, OutputFormat, LanguageCombination, PublicationStatusRequestedMetadata().ToXml())); + var statusObject = new IshObjects(ISHType, statusResponse.xmlObjectList).Objects.FirstOrDefault(); + string currentStatus = (statusObject == null) ? "" : statusObject.IshFields.GetFieldValue(PublicationStatusFieldName, Enumerations.Level.Lng, Enumerations.ValueType.Element); + if (!UnreleaseBeforeRemove(LogicalId + "=" + Version + "=" + LanguageCombination + "=" + OutputFormat, currentStatus, + () => IshSession.PublicationOutput25.SetMetadata(new SetMetadataRequest( + LogicalId, Version, OutputFormat, LanguageCombination, UnreleaseMetadata().ToXml(), "")))) + { + return; + } + } if (ShouldProcess(LogicalId + "=" + Version + "=" + LanguageCombination + "=" + OutputFormat)) { IshSession.PublicationOutput25.Delete(