List of the Macros written in this page :
#* TagClassUpgraderMacro
 *
 * @arg : Name of the old tag manager class
 * @arg : Name of the old tag manager property which contains tags
 * @arg : Name of the new tag manager class
 * @arg : Name of the new tag manager property which contains tags
 * @arg : Request result step
 * @arg : enable/disable safe mode, 0 value switch off the safe mode
 *
 * @desc : This macro replace a tag manager by another in all the documents,
 * you can define a step result. Using a script you are able to send numerous
 * short requests to the server which make him happy, for more information
 * about comand line authentification in xwiki :
 * http://platform.xwiki.org/xwiki/bin/view/Features/BasicAuth
 * BE SURE TO USE VALID PROPERTY NAME IF YOU ARE NOT IN SAFE MODE
 *#
#macro(TagClassUpgraderMacro
 $oldTagManagerName
 $oldTagManagerProp
 $newTagManagerName
 $newTagManagerProp
 $step
 $safeMode)
 #set($sqlRequest = ", BaseObject as obj
  where obj.name=doc.fullName
  and obj.className='$oldTagManagerName'")
 #if($step < 1)
  #set($sqlResult = $xwiki.searchDocuments($sqlRequest))
 #else
  #set($sqlResult = $xwiki.searchDocuments($sqlRequest, $step, 0))
 #end
 # $sqlResult.size()
 #foreach($documentName in $sqlResult)
  #set($documentInstance = $xwiki.getDocument($documentName))
  #set($oldTagManagerInstance = $documentInstance.getObject($oldTagManagerName))
  #set($tags = $oldTagManagerInstance.get($oldTagManagerProp))
  #set($issetNewTagManager = $documentInstance.getObjectNumbers($newTagManagerName))
  #if($issetNewTagManager > 0)
   #set($newTagManagerInstance = $documentInstance.getObject($newTagManagerName))
  #else
   #set($newTagManagerInstance = $documentInstance.newObject($newTagManagerName))
  #end 
  $newTagManagerInstance.set($newTagManagerProp, $tags)
  #if ($safeMode < 1)
   #set($trash = $documentInstance.removeObjects($oldTagManagerName))
  #end
  #if ($documentInstance.hasAccessLevel("edit", $context.getUser()))
   $documentInstance.save()
  #end
 #end
#end

# -> , BaseObject as obj, DBStringListProperty as prop join prop.list list where obj.name=doc.fullName and obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags' and list = 'PersonalInformationManagement'

  • []
* 0
Version 40.1 last modified by Lucien Pereira on 01/08/2008 at 16:04

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: Lucien Pereira on 2008/08/01 10:34
SemanticDesktop.org
1.1.1