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)?
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 = "<xml>" + response.body.storage.value + "</xml>"; xmlBodyText = bodyText .split("ac:").join("ac--") .split("ri:").join("ri--") .split("&nbsp;").join("nnbbsspp") .split("&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("&nbsp;") .split("<xml>").join("") .split("</xml>").join("") .split("/>").join(" />") .split("qquuoott").join("&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)
Thanks Stephen! I will pass the info to the customer. Great support!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could try using the Search and Replace plugin or Bob Swift's 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.