Contacta con nosotros
contacto@flabo.es

Borrar histórico versiones Document Library Liferay

import com.liferay.portlet.documentlibrary.model.*;
import com.liferay.portlet.documentlibrary.service.*;
import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
import com.liferay.portal.util.PropsValues;
import java.io.File;
 
try {
  List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getFileEntries(-1, -1);
  for (DLFileEntry dlFileEntry : dlFileEntries) {
		long companyId = dlFileEntry.getCompanyId();
		long dataRepositoryId = dlFileEntry.getDataRepositoryId();

		List<DLFileVersion> versions = DLFileVersionLocalServiceUtil.getFileVersions(dlFileEntry.getFileEntryId(), -1);
		DLFileVersion latestVersion = DLFileVersionLocalServiceUtil.getLatestFileVersion(dlFileEntry.getFileEntryId(), true);	
		String latestVersionLabel = latestVersion.getVersion();
		
		if(versions != null && versions.size() > 0) {
			for(DLFileVersion version: versions) {
				String versionLabel = version.getVersion();
				if (versionLabel!=latestVersionLabel){
					DLFileVersionLocalServiceUtil.deleteDLFileVersion(version);
				}
			 }
		}
	}

} catch (Exception e) {
  e.printStackTrace();
}