Corrupted main.vmd
Asked by Mariusz:

Hello,

I'm trying to improve searching in conflunence by adding addsearch-category (see below) to main.vmd. I have tested it in our dev environment and it worked fine but when I tried to apply it in my production environment something went wrong (most likely while copying it over) and as a result of I'm not able to access admin pages for layouts.

The addition I've made is in bold:

```
...
#else
<title>$title - #siteTitle()</title>
#end

##Set AddSearch category 
<meta id=search-category name="addsearch-category" content="$sitemeshPage.getProperty("page.spacename")" >

#requireResource("confluence.web.resources:print-styles")

#requireResourcesForContext("main")
...
```

When I try to access /admin/listdecorators.action I get System Error:

```
Cause
org.apache.velocity.exception.MethodInvocationException: Invocation of method 'hasTemplate' in class com.atlassian.confluence.admin.actions.lookandfeel.EditDecoratorAction threw exception java.util.concurrent.CompletionException: java.lang.IllegalStateException: Duplicate key com.atlassian.confluence.core.PersistentDecorator@4b592a3b at /includes/common-listdecorators.vm[line 31, column 30]
at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:337)

caused by: java.util.concurrent.CompletionException: java.lang.IllegalStateException: Duplicate key com.atlassian.confluence.core.PersistentDecorator@4b592a3b
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)

caused by: java.lang.IllegalStateException: Duplicate key com.atlassian.confluence.core.PersistentDecorator@4b592a3b
at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)
```

And when I try to access /admin/editdecorator.action?decoratorName=decorators/main.vmd I get this System Error:

```
Cause
java.util.concurrent.CompletionException: java.lang.IllegalStateException: Duplicate key com.atlassian.confluence.core.PersistentDecorator@4b592a3b
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)

caused by: java.lang.IllegalStateException: Duplicate key com.atlassian.confluence.core.PersistentDecorator@4b592a3b
at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)
```

<br />

I have found the main.vmd file on the server but it doesn't reflect any changes made via the web interface.

Any ideas how can I fix or revert main.vmd back?

Thanks in advance.


Answers:
author: Stephen Sifers
body: Hello Mariusz and welcome to Community!

It does sound like something happened to your main.vmd file. When you replace any files within Confluence, ensure the Confluence service is stopped before doing so, or else corruption may take place. Also, very glad to hear you tested on you dev instance, that's always reassuring to hear!

For replacing your main.vmd file back to its original state, you have a few options. The first would be to restore the file from backups you may have. If you're unable to access your backups then try these steps:

1. Down the version ZIP archive of Confluence version that you are presently running.
   1. [Confluence Server Download Archives](https://www.atlassian.com/software/confluence/download-archives)
2. Once downloaded, extract the ZIP archive.
3. Navigate to 'Confluence\\Decorators' and locate your main.vmd file

Once you have located this file, it can be used to overwrite your corrupted file. Please ensure Confluence is not running, and the services are stopped before overwriting.

If this does not work and you're still receiving errors, please let us know.

Regards,  
Stephen Sifers

comments: author: Mariusz
body: Thank you, I really appreciate your reply.

I'm not sure if this will work as I haven't edited the physical file on the server (which is located: /atlassian-confluence-6.6.11/confluence/decorators/main.vmd) instead I've made the change via confluence interface "General configuration -\> Layouts -\> and clicked edit next to Main Layout"  

In the dev environment, the physical file doesn't contain the changes that I've made in the web interface.

Following your advice, I downloaded the v6.6.11 archive and used diff to compare both main.vmd files and the files are identical! Am I right by thinking that this shouldn't cause the issue and that the physical file is only used as a template for the database?

I was going to try this:

<https://community.atlassian.com/t5/Confluence-questions/Space-Tools-does-not-show-How-to-reset-layout/qaq-p/87818>

Do you think this may work?

Best regards,

Mariusz


author: Stephen Sifers
body: Hello Mariusz,

Thank you for the clarification and comparing your main.vmd files to ensure there is no issue there. As you've explained, the problem is with the edits you've made within your layout.

These edits will need to be reverted for you to see the page again.

First, you may attempt to access the "reset default" button via URL before moving into the SQL work. Here is an example of what the URL would look like:

View your default for Global:

```
http://localhost:8090/admin/viewdefaultdecorator.action?decoratorName=decorators/main.vmd
```

View your default within a Space:

```
http://localhost:8090/spaces/viewdefaultdecorator.action?decoratorName=decorators/main.vmd&key=SPACEKEY
```

Edit your Global layout

```
http://localhost:8090/admin/editdecorator.action?decoratorName=decorators/main.vmd
```

Edit your Space layout:

```
http://localhost:8090/spaces/editdecorator.action?decoratorName=decorators/main.vmd&key=SPACEKEY
```

If the above does not allow you to view your default then edit the existing layout you will need to perform the removal of the layout via the SQL commands from the link you provided.

I would suggest you backup your Confluence instance and database before attempting the workaround within the post you linked. As you've done before, test this on your dev instance to ensure it does remove your layout edits (even though you don't have the same result, you can ensure the layout is removed). Once tested in your dev instance then move to production (After you've completed your backups).

I have had to do a similar task in the past, it was slightly different, but in the end, I did have to drop my changes to the layout to resolve the issue. You may need to adjust the SQL queries within the referenced post to ensure you delete only the changes which are impacting the loading of your page.

Please let us know how the removal goes.

Regards,  
Stephen Sifers


author: Mariusz
body: Morning Stephen,

Unfortunately, I couldn't edit the layouts via the URLs (I've tried that already)and had to do it the dirty way... with help from my work colleague.

After showing the content of decorator table we found duplicated decorators/main.vmd so we removed both of them and were back in business in no time.

Steps to fix the issue:

Show decorators:

```
SELECT decoratorid, decoratorname FROM decorator;
```

Copy the correct IDs and issue:

```
DELETE * FROM decorator WHERE decoratorid='xxxxxxxxx' OR decoratorid='yyyyyyyyy'
```

Thanks for all your help!

Best regards,

Mariusz.


Tags: atl-adm