code for Version Purging | Community
Skip to main content
Sh1ju
New Participant
January 30, 2016
Solved

code for Version Purging

  • January 30, 2016
  • 14 replies
  • 4651 views

Can you please share the code for Version Purging  using  VersionManager (com.day.cq.wcm.api)

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kunal_Gaba_

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. 

14 replies

Sh1ju
Sh1juAuthor
New Participant
February 4, 2016

@ 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)

Sh1ju
Sh1juAuthor
New Participant
February 4, 2016

@kautuksahni,

I tried option [1],got an error 'org.apache.jackrabbit.core.NodeImpl cannot be cast to javax.jcr.version.VersionHistory'

'

kautuk_sahni
Employee
February 1, 2016

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.

  • <cmd>  The value can be "dryrun" OR "purge."  The value "dryrun" helps to preview the purged versions. And, value "purge" launches the purge of the versions on the node that the path defines.
  • <maxdays> The maximum age of the version of a node. When the age of a version exceeds this value, it is purged.
  • <maxversions> The maximum number of versions to keep for a node. When this number exceeds this value, the oldest versions are purged.
  • <path> An absolute path on which the purge is applied.
  • <recursive> When purging data, you can choose between performing the operation on one node or on a whole hierarchy by selecting Recursive.

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

Kautuk Sahni
Jitendra_S_Toma
New Participant
January 30, 2016

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)