Tuesday, August 21, 2012

How to work with Version in CQ

Use Case: 

1) You have to delete specific version from repository
2) You have to create versions using API
3) You have to remove versions
4) Reduce size of repository by removing versions

Background:

CQ uses JCR version management to maintain versions

http://jackrabbit.apache.org/jackrabbit-architecture.html

http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/version/package-summary.html

VersionManger http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/version/VersionManager.html is main service to handle most of task related to versioning.

Within CQ in file systems versions are persisted under /crx-quickstart/repository/version and version index under /crx-quickstart/repository/repository/index

Corresponding configuration is under /crx-quickstart/repository/repository.xml (Which is global configuration)

<Versioning rootPath="${rep.home}/version">
<......>
</Versioning>

Within repository versions are stored under /jcr:system/jcr:versionStorage node, Which is one per repository.

How Versions are created in CQ:

Following actions are responsible for creating version

1) Activation of page (This is controlled by version manager configuration)
http://dev.day.com/docs/en/cq/current/deploying/configuring_cq.html#OSGi%20Configuration%20in%20the%20Repository

Note that from CQ5.5 this configuration is not available by default. You have to create a osgi:Config within repository for this (com.day.cq.wcm.core.impl.VersionManagerImpl).

You can control number of version created by activation by setting versionmanager.maxNumberVersions property.





















2) By sidekick


3) Using API http://www.day.com/specs/jcr/2.0/15_Versioning.html and example http://wiki.apache.org/jackrabbit/ExamplesPage#Versioning_Basics


How to find specific version in CQ

1) Using repository
  • Note that not for all node versions are created. Node has to be of mixin type mix:versionable (node.addMixin("mix:versionable")  
  • Once you are sure that node is of correct mixin type, Find that node using CRX explorer or CRXDE light. 
  • Once node is found find UUID of that node

  • Based on UUID you can find out location of version within repository. Within repository versions are stored like this/jcr:system/jcr:versionStorage/<FIRST TWO LETTER OF UUID>/<NEXT TWO LETTER>/<NEXT TWO LETTER>/<UUID>/<VERSION NUMBER> For example for UUID ce472450-f567-459e-8adc-6fd7a3d8a4f3 you can find it's version under /jcr:system/jcr:versionStorage/ce/47/24/ce472450-f567-459e-8adc-6fd7a3d8a4f3/<Version Number>













2) using API

Something like

VersionManager mgr = session.getWorkspace().getVersionManager();
VersionHistory vh = (VersionHistory) node.getParent().getParent();
VersionIterator vit = vh.getAllVersions();
while (vit.hasNext()) {
Version v = vit.nextVersion();
}

How to Purge Version in CQ

1) Using configuration

http://dev.day.com/docs/en/cq/current/deploying/configuring_cq.html#Configuring%20Version%20Purge

2) Using version Purge Tool

From CQ5.5 onward version purge tool is integrated in CQ that you can use to purge versions

for that go to tools -> versioning -> PurgeVersion
















Purging version will help you to reduce size of repository a lot. You can also configure your repository for not to create versions for other environments (Like dev or staging) 

3 comments:

  1. It has been stated in the blog that the repository could be configured not to create versions for other environments like dev or staging. I would appreciate it if you could let us know how to do this as we are trying to turn off versioning on our publish boxes.

    ReplyDelete
    Replies
    1. Banu,

      You can do that by creating version configuration node under config node. You have to create folder like config.publish or config.publish.dev and add osgi:config (com.day.cq.wcm.core.impl.VersionManagerImpl) under that and disable version creation. More infirmation about how to manage configuration can be found here http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

      Delete
  2. Hi yogesh,

    I have a page already existing in a location /content/test/page1. I want copy new content from from /content/test/temp/page1 into /content/test/page1, before i copy i want to create version of the existing. So i can revert back to the previous version if needed.

    Would that be possible with version manager API?

    ReplyDelete