AtlassianPS / ConfluencePS

Confluence REST API (including Cloud) via PowerShell
https://AtlassianPS.org/module/ConfluencePS
MIT License
149 stars 42 forks source link

ConvertTo-StorageFormat UnknownMacroMigrationException #177

Open ghost opened 4 years ago

ghost commented 4 years ago

Description

Converting a string to confluence storage format with ConvertTo-ConfluenceStorageFormat returns the error com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException.

Steps To Reproduce

[System.String]$JobDescription = @'
<#
    .NOTES
    ===========================================================================
     Created on:
     Created by:
     Created for:
    ===========================================================================
    .DESCRIPTION

        [PSCustomObject[]]$FileToExtend = @(
            [PSCustomObject]@{
                Path = 'C:\Temp\Test.txt' #[System.String]
                LastAccessTime = '12.11.2035' #[System.DateTime]
            },
            [PSCustomObject]@{
                Path = 'C:\Temp\Test.txt' #[System.String]
                LastAccessTime = '12.11.2035' #[System.DateTime]
            }
        )
#>
'@

ConvertTo-ConfluenceStorageFormat -Content $JobDescription
WARNUNG: Confluence returned HTTP error 500 - InternalServerError
Invoke-Method : com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro '
                path = 'c' is unknown.
In .\Modules\ConfluencePS\Public\ConvertTo-StorageFormat.ps1:43 Zeichen:14
+             (Invoke-Method @iwParameters).value
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: ({"statusCode":5... Server Error"}:String) [Invoke-Method], ArgumentException
    + FullyQualifiedErrorId : InvalidResponse.Status500,Invoke-Method

Expected Output

<p>&lt;#<br/>
    .NOTES<br/>
    ===========================================================================<br/>
     Created on:<br/>
     Created by:<br/>
     Created for:<br/>
    ===========================================================================<br/>
    .DESCRIPTION</p>

<p>        [PSCustomObject[]]$FileToExtend = @(<br/>
            [PSCustomObject]@{<br/>
                Path = 'C:\Temp\Test.txt' #[System.String]<br/>
                LastAccessTime = '12.11.2035' #[System.DateTime]<br/>
            },<br/>
            [PSCustomObject]@{<br/>
                Path = 'C:\Temp\Test.txt' #[System.String]<br/>
                LastAccessTime = '12.11.2035' #[System.DateTime]<br/>
            }<br/>
        )<br/>

<p>
#&gt;</p>

Your Environment

Confluence 7.0.1

Get-Host
Name             : Windows PowerShell ISE Host
Version          : 5.1.18362.145

Get-Module -Name ConfluencePS
Name              : ConfluencePS
Description       : PowerShell module to interact with the Atlassian Confluence REST API
Version           : 2.5
lipkau commented 4 years ago

converting an array of c# objects is probably unknown to confluence. what is the output that you are expecting?

lipkau commented 4 years ago

if you are looking for a able format, try this:

[PSCustomObject]@{
    Path = 'C:\Temp\Test.txt' #[System.String]
    LastAccessTime = '12.11.2035' #[System.DateTime]
},
[PSCustomObject]@{
    Path = 'C:\Temp\Test.txt' #[System.String]
    LastAccessTime = '12.11.2035' #[System.DateTime]
} | ConvertTo-ConfluenceTable | ConvertTo-ConfluenceStorageFormat
ghost commented 4 years ago

I would expect the following Output:

<p>&lt;#<br/>
    .NOTES<br/>
    ===========================================================================<br/>
     Created on:<br/>
     Created by:<br/>
     Created for:<br/>
    ===========================================================================<br/>
    .DESCRIPTION</p>

<p>        [PSCustomObject[]]$FileToExtend = @(<br/>
            [PSCustomObject]@{<br/>
                Path = 'C:\Temp\Test.txt' #[System.String]<br/>
                LastAccessTime = '12.11.2035' #[System.DateTime]<br/>
            },<br/>
            [PSCustomObject]@{<br/>
                Path = 'C:\Temp\Test.txt' #[System.String]<br/>
                LastAccessTime = '12.11.2035' #[System.DateTime]<br/>
            }<br/>
        )<br/>

<p>
#&gt;</p>
lipkau commented 4 years ago

The problem with your case is the chars that confluence tries to convert into macros. This works for me using your $JobDescription:

ConvertTo-ConfluenceStorageFormat ($JobDescription -replace "#", "&#35;" -replace "@", "&#64;" -replace "\[", "&#
91;" -replace "\{", "&#123;")
ghost commented 4 years ago

Thank you Oliver, that works for me. I created a pull request (https://github.com/AtlassianPS/ConfluencePS/pull/178). Would be nice to add the ability to handle this cases directly with the function ConvertTo-ConfluenceStorageFormat.