0 Votes

Wiki source code of Script

Version 3.1 by Ryan C on 2025/05/12 21:10

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