How to replace old View File macros with the new File Preview macro
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Confluence 5.7 introduced File Previews as a new way to visualize attachments: Confluence 5.7 Release Notes. In some cases, you might want to replace the old macros in order to use the new features.
Solution
Stop Confluence
Run the following queries in your Confluence database. These steps were tested in PostgreSQL and might need to be adapted to work with a different database server. Each query is for a different type of file:
MS Word
1 2 3 4
UPDATE bodycontent SET body = replace(body, 'ac:name="viewdoc"', 'ac:name="view-file"') WHERE contentid IN (SELECT contentid FROM content WHERE prevver IS null AND contenttype in ('BLOGPOST', 'PAGE', 'COMMENT')) AND body LIKE '%ac:name="viewdoc"%';
MS Excel
1 2 3 4
UPDATE bodycontent SET body = replace(body, 'ac:name="viewxls"', 'ac:name="view-file"') WHERE contentid IN (SELECT contentid FROM content WHERE prevver IS null AND contenttype in ('BLOGPOST', 'PAGE', 'COMMENT')) AND body LIKE '%ac:name="viewxls"%';
MS PowerPoint
1 2 3 4
UPDATE bodycontent SET body = replace(body, 'ac:name="viewppt"', 'ac:name="view-file"') WHERE contentid IN (SELECT contentid FROM content WHERE prevver IS null AND contenttype in ('BLOGPOST', 'PAGE', 'COMMENT')) AND body LIKE '%ac:name="viewppt"%';
PDF
1 2 3 4
UPDATE bodycontent SET body = replace(body, 'ac:name="viewpdf"', 'ac:name="view-file"') WHERE contentid IN (SELECT contentid FROM content WHERE prevver IS null AND contenttype in ('BLOGPOST', 'PAGE', 'COMMENT')) AND body LIKE '%ac:name="viewpdf"%';
Start Confluence
Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
Was this helpful?