murali
murali

Reputation: 41

How to delete the versions for particular space/ document

I had applied the document version at the top level space.. and i copied the 6 documents to the space & edited randomly & it is created the versions.. I want to delete the all the previous versions in the space.. how can i achieve this one..

This is not a mad question, This is one of my client requirement...

Please give any suggestions to achieve this...

Thanks Murali

Upvotes: 1

Views: 2581

Answers (2)

Tahir Malik
Tahir Malik

Reputation: 6643

I guess as simple as this:

import java.util.List;

import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.VersionService;

public class DeleteVersionHistoryActionExecuter extends ActionExecuterAbstractBase{

    private VersionService versionService;

    @Override
    protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
        versionService.deleteVersionHistory(actionedUponNodeRef);

    }

    @Override
    protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
        // TODO Auto-generated method stub

    }

    public void setVersionService(VersionService versionService) {
        this.versionService = versionService;
    }
}

And define the ActionExecuter in a *.context.xml file

<?xml version='1.0' encoding='UTF-8'?>

<bean name="deleteVersionHistoryAction" class="com.your.package.DeleteVersionHistoryActionExecuter" parent="action-executer">
    <property name="versionService" ref="versionService" />
</bean>

Now restart your Alfresco, you can now use your ActionExecter. With the runas functionality, or defining a rule on a folder, where the action gets triggerd.

Upvotes: 4

skuro
skuro

Reputation: 13514

The VersionService provides both deleteVersion and deleteVersionHistory. There's currently no way to access such methods via Javascript, so you need to code some Java. I'd suggest you to write a custom Java Action that calls such methods.

Upvotes: 2

Related Questions