воскресенье, 18 декабря 2011 г.

How to purge old versions

Hi. Today I am going to write about how to Purge old versions in Tridion.
Tridion 2011 has Purge tool which allows you to delete old versions of items. You probably have seen and used it.

In Tridion 2011 SP1 we provided a new method for Tom.Net API. 
You can find "PurgeOldVersions" method in session.SystemManager class. 
This method can be called only bt Administrator. In order to use PurgeOldVersion APi you have to create your own PurgeOldVersionsInstruction.
Like other instructions ,to which you already get used, that Tridion has, it has properties that you have to specify. Here are a list of properties:

  • VersionsToKeep - set how many versions we must keep.
  • Recursive - set how deep we should do our purge.
  • KeepVersionsModifiedAfter - specify date and keep versions which are going after this date.
  • KeepVersionsWithinDaysBeforeLastCheckIn - specify days within last modification to keep versions.
  • Containers - specify publications(repositories) and organizational items (only folders and structure groups) in which we can peform purge. If another item pushed to this collection, InvalidActionException will be raised. If input value = null or empty enumeration we have no restrictions for search location and process it on all items in System.
  • MaxResolvedVersioneditemsCount - considering, that our search can return a big amount of items we can set max number of items which we can select for purging during this iteration of our functionality. Default value = 0 (Select all items without count restriction).
  • DefaultMaxResolvedVersionedItemsCount- Upper limit(and default value) of items, which can be purged during one purging iteration. By default value is equal to 100.000.

Here is a simple example how to use this method via Tom.Net

using (Session session = new Session(user))
 PurgeOldVersionsInstruction instruction = new PurgeOldVersionsInstruction(session)
 { Recursive = false,
   VersionsToKeep = 10,
   KeepVersionsModifiedAfter = new DateTime(2011,7,28,23,17,0),
   KeepVersionsWithinDaysBeforeLastCheckIn = 1,
   MaxResolvedVersionedItemsCount = 40
  StructureGroup folder =
  List<IContainer> list = new List<IContainer>();
  instruction.Containers = list;