How to purge Asset Versions in AEMaaCS?
Hi,
How to purge the asset version in aem programmatically?
Configured OOTB Day CQ WCM Version Manager configuration to purge the versions but in this case not all the versions getting purged atleast 1 version will be there in the asset.

Tried to get version programmatically and delete the versions but same issue here as well purge will work only if the versions are more than 1.
VersionManager versionManager = session.getWorkspace().getVersionManager();
VersionHistory versionHistory = versionManager.getVersionHistory(assetPath);
Iterator<Version> versions = versionHistory.getAllVersions();
while (versions.hasNext()) {
Version version = versions.next();
String versionName = version.getName();
String versionPath = version.getPath();
if (!"jcr:rootVersion".equals(versionName)) {
versionHistory.removeVersion(versionName);
}
}
I want a code which deletes all the versions of asset. Just keep the original version.
I tried deleting the property "mix:versionable" from the asset which is working and deleting all the versions. But when I upload newer version again all the older versions are getting added. Not sure whether the version is getting deleted or the version is getting unlinked when I run this code.
Node assetNode = session.getNode(assetPath);
if (assetNode.isNodeType("mix:versionable")) {
assetNode.removeMixin("mix:versionable");
session.save();
}
Please let me know if this is the right way. If not please share the appropriate way to delete all the asset versions.
Thanks.
