Hi, would like to ask how can I get the all the versions of the page. I've tried the following code
ResourceResolver rr = currentResource.getResourceResolver();
PageManager pageManager = rr.adaptTo(PageManager.class);
Page page = pageManager.getPage(currentResource.getPath());
Session session = rr.adaptTo(Session.class);
VersionManager versionManager = session.getWorkspace().getVersionManager();
VersionHistory versionHistory = versionManager.getVersionHistory(page.getPath());
VersionIterator versionIterator = versionHistory.getAllVersions();
if (versionIterator.hasNext()) {
Version firstVersion = versionIterator.nextVersion();
////////////////Some codes here/////////////
}
and when it gets to
VersionHistory versionHistory = versionManager.getVersionHistory(page.getPath());
it would throw an exception
javax.jcr.UnsupportedRepositoryOperationException: Node at /content/acom/us-en/about/sample-page is not versionable.
Reason that I need to get the version history is that I need to get the value of the date for the Version 1.0 of the page. Or are there any other way to do that.
*Note: this line of code is added on the Replication/publish action.
Thanks!
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @LyonMartin,
In general your code looks correct. The problem is that you are passing path to page, represented by cq:Page node in repository, to make it work you should point to cq:PageContent node which is direct child of your page. According to the documentation getVersionHistory method requires path to node that is versionable, in other case UnsupportedRepositoryOperationException is thrown.
In other words, if your page path is /content/sample/en/page, and you would like to access versions of that page you should use this path /content/sample/en/page/jcr:content
Please change your code as follow:
// Replace below line in your code
VersionHistory versionHistory = versionManager.getVersionHistory(page.getPath());
// with this
VersionHistory versionHistory = versionManager.getVersionHistory(page.getContentResource().getPath());
// or with this
VersionHistory versionHistory = versionManager.getVersionHistory(page.getPath() + "/jcr:content");
@LyonMartin Below sample code should work. can you give it a try
Hi, exception is still encountered.
javax.jcr.UnsupportedRepositoryOperationException: Node at /content/acom/us-en/sample-page is not versionable
Hi @LyonMartin,
In general your code looks correct. The problem is that you are passing path to page, represented by cq:Page node in repository, to make it work you should point to cq:PageContent node which is direct child of your page. According to the documentation getVersionHistory method requires path to node that is versionable, in other case UnsupportedRepositoryOperationException is thrown.
In other words, if your page path is /content/sample/en/page, and you would like to access versions of that page you should use this path /content/sample/en/page/jcr:content
Please change your code as follow:
// Replace below line in your code
VersionHistory versionHistory = versionManager.getVersionHistory(page.getPath());
// with this
VersionHistory versionHistory = versionManager.getVersionHistory(page.getContentResource().getPath());
// or with this
VersionHistory versionHistory = versionManager.getVersionHistory(page.getPath() + "/jcr:content");
This one works for me. Thank you so much!
The error you're encountering, javax.jcr.UnsupportedRepositoryOperationException: Node at /content/acom/us-en/about/sample-page is not versionable
, indicates that the page you're trying to retrieve the version history for hasn't been made versionable in the JCR (Java Content Repository). In AEM, not all nodes are versionable by default; versioning needs to be explicitly enabled for specific nodes.
To make a node versionable, it must be of a type that supports versioning, typically by including a mixin of type mix:versionable
. This is usually handled by AEM for content under /content
when you activate (replicate) a page, but there can be cases where this might not occur automatically, or custom content might not be set up to be versionable.
Ensure Page Versioning is Enabled:
mix:versionable
mixin on the node. If it's not present, the node isn't versionable, and hence you can't retrieve its version history.Making a Node Versionable (if applicable):
Alternative Approach to Retrieve Version Creation Date:
Thank you. I will take note of this
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies