Content versions

Enonic version: 6.0.0
OS: Debian Linux

I am writing av ScriptBean that fetches versions by contentId, this works fine. Is it possible to fetch content of previous versions ?

I’ve tried this:

public ContentsResultMapper getVersions(){
        try{
            FindContentVersionsResult versions = contentService.getVersions(FindContentVersionsParams.create().contentId(ContentId.from(contentId)).from(0).size(3).build());
            List<String> contentIds = new ArrayList<>((int) versions.getHits());
            versions.getContentVersions().forEach(contentVersion -> contentIds.add(contentVersion.getId().toString()));
            return new ContentsResultMapper(contentService.getByIds(new GetContentByIdsParams(ContentIds.from(contentIds))), 10);
        }catch (NodeNotFoundException ignored){
            LOG.info("Found no versions for contentId: " + contentId);
            return new ContentsResultMapper(Contents.empty(), 0);
        }
    }

But getByIds with the version id does not work, is this possible at all ?

Hi.

At the moment, Im afraid that its not possible to fetch a specific version of a Content. The getByIds are expecting contentId’s, not versionIds, so your method here will not return anything. I think @tsi will be able to tell you something about when this will be implemented.

Afraid you’ll have to wait for 7.0 for this, we’re planning some refactoring in how we handle versions. ETA is most likely Q1 2016. Sorry bout that.

Is there any way to clear the unused content versions to shrink the repository size?
We have a big client repository on 5.3 that needs shrinking before migration, any tips?

No need for shrinking as old versions are actually not migrated! Funny how that could actually be a good thing :slight_smile: