How to migrate a macro 3x to 4x in existing content
Asked by Salvatore "Sax" Cammarata:

Hi,

A customer just migrated from a 3.5 to a 5.8 version of Confluence.

Unfortunately the macro migration failed and the wiki pages now contain the old version of the macro:

      <ac:structured-macro ac:macro-id="08531f28-34b3-41b9-8297-0a85e7b1be97" ac:name="mockup" ac:schema-version="1">    <ac:parameter ac:name="1">28</ac:parameter>    <ac:parameter ac:name="">test</ac:parameter>  </ac:structured-macro>

And this is how it should look like in order for the plugin content to be displayed properly:

    <ac:structured-macro ac:macro-id="08531f28-34b3-41b9-8297-0a85e7b1be97" ac:name="mockup" ac:schema-version="1"> 
     <ac:parameter ac:name="Version">28</ac:parameter> 
     <ac:parameter ac:name="Name">test</ac:parameter> 
    </ac:structured-macro>

Unfortunately the rolling back to 3.5 is not an option.

Is there a way to convert the macro in existing content outside the migration process (e.g. some sort of script)?


Answers:
author: Stephen Deutsch
body: Since the macro values are dynamic, it could be that a standard search/replace might not work. However, Confluence's storage format is (more or less) valid XML, so you can use the browser engine to parse it via Javascript. This is what I was able to throw together, but I can't guarantee it will work on all pages:

```
jQuery.ajax({    url: contextPath + "/rest/api/content/" + AJS.params.pageId + "?expand=body.storage,version,ancestors",    success: function(response) {        console.log(response);        bodyText = "&lt;xml&gt;" + response.body.storage.value + "&lt;/xml&gt;";        xmlBodyText = bodyText            .split("ac:").join("ac--")            .split("ri:").join("ri--")            .split("&amp;nbsp;").join("nnbbsspp")            .split("&amp;quot;").join("qquuoott");        xmlDoc = jQuery.parseXML(xmlBodyText);        xml = jQuery(xmlDoc);        macro = xml.find('ac--structured-macro[ac--name="mockup"]');        jQuery(macro).each(function() {            jQuery(this).find("ac--parameter").eq(0).attr("ac--name", "Version");            jQuery(this).find("ac--parameter").eq(1).attr("ac--name", "Name");        });        ser = new XMLSerializer();        newBodyText = ser.serializeToString(xml[0]);        newBodyText = newBodyText            .split("ac--").join("ac:")            .split("ri--").join("ri:")            .split("nnbbsspp").join("&amp;nbsp;")            .split("&lt;xml&gt;").join("")            .split("&lt;/xml&gt;").join("")            .split("/&gt;").join(" /&gt;")            .split("qquuoott").join("&amp;quot;");        response.body.storage.value = newBodyText;        response.version.number += 1;        jQuery.ajax({            contentType: 'application/json',            type: 'PUT',            url: contextPath + "/rest/api/content/" + AJS.params.pageId,            data: JSON.stringify(response),            success: function(response) {                console.log(response);            },            error: function(response) {                console.log(response);            }        });    }});
```

You can paste this JS in the browser console, and it should be able to replace the macro parameters in the page with the proper values. It only works on a page-by-page basis, but it should be easily adaptable to search for all pages containing the macro.

EDIT: Forgot to include "ancestors" in the URL string (needed in order to keep the same place in the page hierarchy)

comments: author: Salvatore "Sax" Cammarata
body: Thanks Stephen! I will pass the info to the customer.Great support!


author: Lukas Knoch -Rumpelcoders-
body: You could try using the [Search and Replace](https://marketplace.atlassian.com/plugins/at.rumpelcoder.confluence.search-and-replace) plugin or Bob Swift's [How to globally search and modify content](https://bobswift.atlassian.net/wiki/display/CSOAP/How+to+globally+search+and+modify+content) to replace the parameters with the correctly named ones.

If you decide to use the plugin, feel free to ask for more help here.

Best, Lukas


Tags: macro