0 Votes

Wiki source code of Script

Version 4.1 by Ryan C on 2025/05/12 23:33

Hide last authors
Ryan C 1.1 1 {{groovy}}
Ryan C 4.1 2 import org.xwiki.model.reference.DocumentReference
Ryan C 1.1 3
Ryan C 4.1 4 def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup")
5 def groupClassRef = new DocumentReference("xwiki", "XWiki", "XWikiGroups")
6 def mainGroupDoc = xwiki.getDocument(groupDocRef).getDocument()
7
Ryan C 1.1 8 def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'")
9 def added = []
10
11 allUsers.each { userDocName ->
Ryan C 3.1 12 def alreadyMember = mainGroupDoc.getXObjects(groupClassRef)?.any {
13 it?.getStringValue("member") == userDocName
14 }
Ryan C 1.1 15
16 if (!alreadyMember) {
Ryan C 2.1 17 def newObj = mainGroupDoc.newXObject(groupClassRef)
Ryan C 1.1 18 newObj.setStringValue("member", userDocName)
19 added << userDocName
20 }
21 }
22
23 if (added) {
Ryan C 4.1 24 def mainGroupWrapped = xwiki.getDocument(mainGroupDoc.documentReference)
25 xwiki.saveDocument(mainGroupWrapped, "Added missing users to XWikiAllGroup: ${added.join(', ')}")
Ryan C 1.1 26 println "✅ Added users to main wiki: ${added.join(', ')}"
27 } else {
28 println "✅ All users are already members of the main wiki."
29 }
30 {{/groovy}}
31