воскресенье, 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 =
  (StructureGroup)session.GetObject("tcm:2-4-4");
  List<IContainer> list = new List<IContainer>();
  list.Add(folder);
  instruction.Containers = list;
                    session.SystemManager.PurgeOldVersions(instruction);    
}

4 комментария:

  1. That's great news. I remember having to work on the purge tool back in the day, and ending up doing remedial work on the UI. Part of the problem was that we had to support a screen resolution that you'd laugh at these days - hence those tabs - sorry folks!

    Maybe now the old purge tool can be given a dignified exit. :-)

    ОтветитьУдалить
  2. Is this exposed in the Core Service too? We're not supposed to use TOM.NET anymore for this type of tools...

    [Sorry, I didn't check it yet, just wondering if you know by heart]

    N

    ОтветитьУдалить
    Ответы
    1. Hi Nuno. Yeap indeed you are not suppose to use TOM.net. There is no such Api for Core Service, but It probably will be in a next version.

      Удалить
  3. Nice. One point we've seen on the TridionWorld forum is we need to be a user with the right permissions and rights to use the Purge Tool (or any of the Tridion APIs or tools).

    I teased a colleague that of course you need authorization with an API (in that chat it was the Core Service). Otherwise anyone with the right access (or creative hacking) can destroy production content.

    Thanks for sharing, I know of the tool, but have never been in role that let me run it!

    ОтветитьУдалить