0 Votes

Changes for page Script

Last modified by Ryan C on 2025/05/13 16:08

From version 4.1
edited by Ryan C
on 2025/05/12 23:33
Change comment: There is no comment for this version
To version 1.1
edited by Ryan C
on 2025/05/12 18:20
Change comment: There is no comment for this version

Summary

Details

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