Can you please share the code for Version Purging using VersionManager (com.day.cq.wcm.api)
Solved! Go to Solution.
Views
Replies
Total Likes
Sh1ju wrote...
@ Jitendera ,Its already versionable.please check the screen shot
The versionable mixin is applied on jcr:content node whereas in your code you are trying to do the operation on mm1 node which may not have the mixin.
Views
Replies
Total Likes
Hi,
Here is the code which does the purging. I have not tested this code. However, it seems quite good.
http://wemcode.wemblog.com/version-purging
Here is the configuration doc which explains important attributes needed for purging tool
https://docs.adobe.com/docs/en/aem/6-1/deploy/configuring/version-purging.html#Purge Versions Tool
Jitendra
Sh1ju wrote...
Can you please share the code for Version Purging using
VersionManager (com . day. cq . wcm . api )
Views
Replies
Total Likes
As mentioned by Jitendera,
Option 1:-
Link:- http://wemcode.wemblog.com/version-purging
would help you in writing a code to do version purging.
//
VersionManager mgr = session.getWorkspace().getVersionManager();
// get version history
VersionHistory vh = (VersionHistory) node.getParent().getParent();
// VersionHistory vh = mgr.getVersionHistory(path);
String id = vh.getIdentifier();
// get the names of the versions
List<String> names = new LinkedList<String>();
VersionIterator vit = vh.getAllVersions();
while (vit.hasNext()) {
Version v = vit.nextVersion();
if (!v.getName().equals("jcr:rootVersion")) {
names.add(v.getName());
}
}
// remove all versions
for (String name: names) {
vh.removeVersion(name);
}
option 2:- Using CURL
Link:- https://helpx.adobe.com/experience-manager/kb/curl-command-version-purge.html
//
Using cron job, schedule the curl commands [1], and then remove the progress file. The following list explains the various input parameters.
For more details, click here.
An example of curl command to purge everything except last five versions for the tree/content/geometrixx/en/test is [2] & [3].
[1]
curl -u <userid>:<password> -f -o progress.txt -d "cmd=<cmd>&maxdays=<maxdays>&maxversions=<maxversions>&path=<path>&recursive=<recursive>" "http://<host>:<port>/etc/versioning/purge.html"
[2]
curl -u admin:admin -f -o progress.txt -d "cmd=purge&maxdays=0&maxversions=5&path=/content/geometrixx/en/test&recursive=true" "http://localhost:4502/etc/versioning/purge.html"
[3]
rm progress.txt
Reference Link:- https://cqwemblog.wordpress.com/2013/11/29/how-to-remove-page-version-under-a-content-tree/
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
I tried option [1],got an error 'org.apache.jackrabbit.core.NodeImpl cannot be cast to javax.jcr.version.VersionHistory'
'
Views
Replies
Total Likes
@ Jitendera, I tried your solution but got an error
UnsupportedRepositoryOperationException javax.jcr.UnsupportedRepositoryOperationException: Unable to perform a versioning operation on a non versionable node: /content/geometrixx/mm/m1
at org.apache.jackrabbit.core.version.VersionManagerImplBase.checkVersionable(VersionManagerImplBase.java:293)
at org.apache.jackrabbit.core.version.VersionManagerImplBase.getVersionHistory(VersionManagerImplBase.java:354)
at org.apache.jackrabbit.core.VersionManagerImpl.access$700(VersionManagerImpl.java:73)
at org.apache.jackrabbit.core.VersionManagerImpl$4.perform(VersionManagerImpl.java:184)
at org.apache.jackrabbit.core.VersionManagerImpl$4.perform(VersionManagerImpl.java:180)
at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
at org.apache.jackrabbit.core.VersionManagerImpl.perform(VersionManagerImpl.java:96)
at org.apache.jackrabbit.core.VersionManagerImpl.getVersionHistory(VersionManagerImpl.java:180)
at com.mm.online.cms.aem.archival.MMUtility.clearOldVersions(MMUtility.java:282)
at com.mm.online.cms.aem.archival.impl.CleanUpServiceImpl.cleanup(CleanUpServiceImpl.java:260)
at com.mm.online.cms.aem.archival.impl.CleanUpServiceImpl.run(CleanUpServiceImpl.java:228)
at org.apache.sling.commons.scheduler.impl.QuartzJobExecutor.execute(QuartzJobExecutor.java:105)
at org.quartz.core.JobRunShell.run(JobRunShell.java:207)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Views
Replies
Total Likes
Have you enable this node to make versionable?. Just verify whether it has a property (mix:versionable ) for version. If not, please add and then try it.
Ideally, this property should be at template level so that you don't need to add manually at individual pages.
Jitendra
Views
Replies
Total Likes
@ Jitendera ,Its already versionable.please check the screen shot
Views
Replies
Total Likes
Views
Replies
Total Likes
I didn't notice at first glance, But we are doing purging here. How does your code throws an exception which is more like "Not able to create version on a particular page."
Are you sure this exception is related to purging?.
Jitendra
Views
Replies
Total Likes
@Jitendra please find the code
public void clearOldVersions(Session session,String nodePath,Logger logger)
{
VersionManager versionManager = null;
VersionHistory versionHistory = null;
VersionIterator versionItr = null;
logger.debug("Starting clearOldVersions..");
try {
versionManager = session.getWorkspace().getVersionManager();
} catch (UnsupportedRepositoryOperationException e)
{
logger.error("UnsupportedRepositoryOperationException",e);
} catch (RepositoryException e) {
logger.error("RepositoryException",e);
}
try {
versionHistory = versionManager.getVersionHistory(nodePath);
} catch (UnsupportedRepositoryOperationException e) {
logger.error("UnsupportedRepositoryOperationException",e);
} catch (RepositoryException e) {
logger.error("RepositoryException",e);
}
// below return all versions in order of creation date
try {
versionItr = versionHistory.getAllVersions();
} catch (RepositoryException e) {
logger.error("RepositoryException",e);
}
//Since we know MaxVersion number then we need to iterate it accordingly.
// get the names of the versions
List<String> names = new LinkedList<String>();
while (versionItr.hasNext()) {
Version v = versionItr.nextVersion();
try {
if (!v.getName().equals("jcr:rootVersion")) {
versionHistory.removeVersion(v.getName());
logger.debug("Removing the version of "+nodePath);
}
} catch (AccessDeniedException e) {
logger.error("AccessDeniedException",e);
} catch (ReferentialIntegrityException e) {
logger.error("ReferentialIntegrityException",e);
} catch (UnsupportedRepositoryOperationException e) {
logger.error("UnsupportedRepositoryOperationException",e);
} catch (VersionException e) {
logger.error("VersionException",e);
} catch (RepositoryException e) {
logger.error("RepositoryException",e);
}
}
logger.debug("clearOldVersions....completed");
}
Views
Replies
Total Likes
Give me some time. Will get back to you very soon. Trying to validate your code.
Jitendra
Views
Replies
Total Likes
Hi,
Have you tried purging versions using OOTB service?.
Day CQ WCM Version Purge Task
Jitendra
Views
Replies
Total Likes
Hi,
If you are using AEM 6.0/6.1, here is another tool which could help you purging versions.
http://localhost:4502/etc/versioning/purge.html
Sh1ju wrote...
Can you please share the code for Version Purging using VersionManager (com.day.cq.wcm.api)
Views
Replies
Total Likes
Views
Replies
Total Likes
The wemblog code removes all newer versions except the base version, which is probably not what you want (keep the latest version only).
To get the code:
Views
Replies
Total Likes
Views
Likes
Replies