0 Votes

Changes for page Script

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

From version 2.1
edited by Ryan C
on 2025/05/12 18:22
Change comment: There is no comment for this version
To version 3.1
edited by Ryan C
on 2025/05/12 21:10
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,5 +1,5 @@
1 1  {{groovy}}
2 -def mainGroupDoc = xwiki.getDocument("XWiki.XWikiAllGroup")
2 +def mainGroupDoc = xwiki.getDocument("XWiki.XWikiAllGroup").getDocument()
3 3  def groupClassRef = "XWiki.XWikiGroups"
4 4  
5 5  def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'")
... ... @@ -7,8 +7,9 @@
7 7  
8 8  allUsers.each { userDocName ->
9 9   def userDoc = xwiki.getDocument(userDocName)
10 - def existing = mainGroupDoc.getXObjects(groupClassRef)
11 - def alreadyMember = existing?.any { it?.getStringValue("member") == userDocName }
10 + def alreadyMember = mainGroupDoc.getXObjects(groupClassRef)?.any {
11 + it?.getStringValue("member") == userDocName
12 + }
12 12  
13 13   if (!alreadyMember) {
14 14   def newObj = mainGroupDoc.newXObject(groupClassRef)
... ... @@ -18,7 +18,7 @@
18 18  }
19 19  
20 20  if (added) {
21 - xwiki.saveDocument(mainGroupDoc, "Added missing users to XWikiAllGroup: ${added.join(', ')}")
22 + xwiki.saveDocument(mainGroupDoc.newDocument(), "Added missing users to XWikiAllGroup: ${added.join(', ')}")
22 22   println "✅ Added users to main wiki: ${added.join(', ')}"
23 23  } else {
24 24   println "✅ All users are already members of the main wiki."