Hi everyone,
I'm currently trying to restore version on multiple pages.
I'm using :
pageManager.restore(pageToRestore.getPath(), revision.getId());
On some pages I got this issue :
com.day.cq.wcm.api.WCMException: Unable to restore version.
at com.day.cq.wcm.core.impl.page.PageManagerImpl.restore(PageManagerImpl.java:1178) [com.day.cq.wcm.cq-wcm-core:5.12.188]
...
Caused by: javax.jcr.nodetype.ConstraintViolationException: Property is protected: jcr:created = 2023-06-14T10:55:59.526Z
When I checked in the crx/de, this page has the jcr:created property marked as protected and auto created (On some other pages this property is not protected).
I tried to create a page from scratch with the interface and create / restore a version also with the interface and it works well whereas the property was also marked as protected ...
I don't understand why it is not working while using the pageManager.
Thanks a lot for any help.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi everyone, as often in this situation, the issue was between the chair and the keyboard ....
I didn't notice that previously in my code I was updating the pages properties and I was updating the jcr:primaryType ... causin the issue.
Sorry to have lost your time and thanks a lot for your answers anyway.
Best !
Views
Replies
Total Likes
In AEM, certain properties like jcr:created
are marked as protected to ensure their integrity and consistency. These properties are typically auto-generated and managed by the system, and modifying them directly is restricted to maintain data integrity.
To resolve this issue when using pageManager.restore()
, you can follow these steps:
jcr:created
value of the page before attempting to restore the version.pageManager.restore()
, reset the jcr:created
property to its original value obtained in step1.Value originalCreatedValue = pageToRestore.getProperties().get("jcr:created");
try {
// Restore the version
pageManager.restore(pageToRestore.getPath(), revision.getId());
// Reset the jcr:created property to its original value
pageToRestore.setProperty("jcr:created", originalCreatedValue);
// Save the changes
pageManager.getSession().save();
} catch (WCMException e) {
// Handle the exception
}
Views
Replies
Total Likes
Hi,
Thanks for your answer.
The issue here is that the line
pageManager.restore(pageToRestore.getPath(), revision.getId());
is not working, because of the jcr:created property
I go in the catch part directly
Views
Replies
Total Likes
you have to remove the protection from the jcr:created
property, then only you should be able to restore the version of the page successfully using the pageManager.restore()
method.
Check if the page has the jcr:created
property marked as protected. If it does, remove the protection before restoring the version:
Views
Replies
Total Likes
Sorry to ask this but I am not able to found out how to remove the protection on the property
Do you have the technical documentation to use ?
Many thanks
Views
Replies
Total Likes
Hello @emiliec9783492
The pages that are having issues with restore:
- have these been created via OOTB AEM Page creation ability?
- have their versions been created via OOTB AEM versioning ability?
- Are you able to restore them via OOTB AEM version restore?
Views
Replies
Total Likes
Hi @aanchal-sikka !
The pages have been created with the OOBgraphical interface.
Their versions have been created by code with pageManager :
pageManager.createRevision(pageWhichNeedRevision, revisionName,""
I am able to restore the version with the OOB graphical interface, but not by code with the page manager method
Views
Replies
Total Likes
The code OOTB would also be
Page page = pageManager.restore(pagePath, id);
1. Please see if the id that is being passed from UI and the one you are restoring are they same. Move between same versions.
2. Check the permissions of the user, whose session you are using. Try to provide all access to this user and try. For quick result add the user to administrators group and try. We will come to know, if its data issue or access issue
Views
Replies
Total Likes
I had great hope in your suggestion as I was using a session with a custom user ... howewer I tried to use :
try (final ResourceResolver resolver = resolverFactory.getAdministrativeResourceResolver(null)) {
pageManager = resolver.adaptTo(PageManager.class);
...
pageManager.restore(pageToRestore.getPath(), revision.getId());
To be sure, and even with me being an admin, I still got the same issue
com.day.cq.wcm.api.WCMException: Unable to restore version.
Caused by: javax.jcr.nodetype.ConstraintViolationException: Property is protected: jcr:created = 2023-06-14T10:55:59.526Z
I really don't catch it >-<
Views
Replies
Total Likes
By default, jcr:created on Page node cannot be edited. Thus is protected and auto-created.
Same is in version node as well.
Are you facing issue, where the property is protected or available for edit (either in version/page)? Basically a mismatch of the Protected attribute.
Views
Replies
Total Likes
Hi everyone, as often in this situation, the issue was between the chair and the keyboard ....
I didn't notice that previously in my code I was updating the pages properties and I was updating the jcr:primaryType ... causin the issue.
Sorry to have lost your time and thanks a lot for your answers anyway.
Best !
Views
Replies
Total Likes
Views
Likes
Replies