Groovy script that would scanned all the objects of a classe in all wiki

With a Groovy script with admin rights I would like to scan all the objects of the class “XWiki.XWikiGlobalRights” for all the wiki.
The aim is too eventually modify some properties values.
With the following code I obtain the name of all the wikis.
List lIsteDesWikis;
lIsteDesWikis = xwiki.getWikiNames();
But after how to change of context for getting objects of a specific wiki ?

By advance, thanks.

Hi Camille,

See which will lead you to

Note: I’ve just added these documentation content to answer your question , hope you appreciate :wink:

Hi Vincent.

I have done this sGroovy script before I get your answer :

import com.xpn.xwiki.api.XWiki;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.Level;
import org.xwiki.model.reference.DocumentReference;
import com.xpn.xwiki.api.Document;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.internal.mandatory.XWikiGlobalRightsDocumentInitializer;
import com.xpn.xwiki.doc.XWikiDocument; 

Logger logger = services.logging.getLogger(doc.fullName);
logger.debug("Début du script 'DeleteDuplicateXWikiXWikiGlobalRigtsObjects.groovy'");

def classeXWikiGlobalRights = xwiki.getClass("XWiki.XWikiGlobalRights");

List<String> listeDesWikis;

listeDesWikis = xwiki.getWikiNames();

println "Liste of the wikis:"
for (currentWikiName in listeDesWikis) {
	println "* ${currentWikiName}";

for (currentWikiName in listeDesWikis) {
	println "=Wiki '${currentWikiName}'=";
	DocumentReference documentReference = new DocumentReference(currentWikiName, ["XWiki"], "XWikiPreferences");
	try {
		Document currentWikiDocument = xwiki.getDocument(documentReference);
		Vector<Object> vectorObject;
	    vectorObject = currentWikiDocument.getObjects("XWiki.XWikiGlobalRights");
	    String txt = "${vectorObject.size()} objects of the classe 'XWiki.XWikiGlobalRights'  found in 'XWikiPreferences' of the wiki '${currentWikiName}'.";
	    println txt;

		String ligneTitre1, ligneTitre2;
		ligneTitre1 = "|#";
		for (prop in{
			ligneTitre1 =  ligneTitre1 + "|${prop.prettyName}\n(${})";
		println ligneTitre1;
		int occurence = 0;

		for (currentObject in vectorObject) {
			String ligne = "|" + occurence;
			Boolean found = false;
			for  (prop in{
				ligne = ligne +  "|${currentObject.get(}";
			println ligne;
			occurence = occurence + 1;
	} catch (XWikiException e){
		logger.error("Document 'XWikiPreferences' not found  for the wiki '${currentWikiName}'.");	      
		logger.error("Exception during the call of getDocument() : ${e}");

The problem with this code is that the API get a “cleaned” name of the “groups” property.
For example I will get “XWikiAllgroup” instead of “xwiki:XWiki.XWikiAllgroup” for the global group or “XWiki.XWikiAllgroup” for the local group related to the current wiki.

What is the best way to get the real “groups” value ?

What is the supposed effect of the class “XWikiGlobalRightsDocumentInitializer” ? I tried to use it on each wiki without success. It issued a “null point exception” when it call the method “updateDocument(XWikiDocument document)” despite my document is not null (Generated Documentation (Untitled)).

Par avance, merci.
Camille desmots