How to replace old View File macros with the new File Preview macro
Platform Notice: Data Center Only - This article only applies to Atlassian apps 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
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
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
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
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
Warning: Backup your database before proceeding.
Before running any SQL in this article, create a full backup of your Jira database. This is a database-level operation with no undo other than restoring from backup. Only proceed if you're comfortable running SQL directly against the Jira database, and test on a staging or cloned environment first, wherever possible.
Was this helpful?