0 Votes

Changes for page Script

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

From version 5.1
edited by Ryan C
on 2025/05/12 23:35
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,18 +1,18 @@
1 1  {{groovy}}
2 -def groupDocRef = "XWiki.XWikiAllGroup"
3 -def groupClassName = "XWiki.XWikiGroups"
2 +def mainGroupDoc = xwiki.getDocument("XWiki.XWikiAllGroup")
3 +def groupClassRef = "XWiki.XWikiGroups"
4 4  
5 -def mainGroupDoc = xwiki.getDocument(groupDocRef).getDocument()
6 6  def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'")
7 7  def added = []
8 8  
9 9  allUsers.each { userDocName ->
10 - def alreadyMember = mainGroupDoc.getXObjects(groupClassName)?.any {
9 + def userDoc = xwiki.getDocument(userDocName)
10 + def alreadyMember = mainGroupDoc.xObjects(groupClassRef)?.any {
11 11   it?.getStringValue("member") == userDocName
12 12   }
13 13  
14 14   if (!alreadyMember) {
15 - def newObj = mainGroupDoc.newXObject(groupClassName)
15 + def newObj = mainGroupDoc.newObject(groupClassRef)
16 16   newObj.setStringValue("member", userDocName)
17 17   added << userDocName
18 18   }
... ... @@ -19,8 +19,7 @@
19 19  }
20 20  
21 21  if (added) {
22 - def wrappedDoc = xwiki.getDocument(mainGroupDoc.documentReference)
23 - xwiki.saveDocument(wrappedDoc, "✅ Added users to XWikiAllGroup: ${added.join(', ')}")
22 + xwiki.saveDocument(mainGroupDoc, "Added missing users to XWikiAllGroup: ${added.join(', ')}")
24 24   println "✅ Added users to main wiki: ${added.join(', ')}"
25 25  } else {
26 26   println "✅ All users are already members of the main wiki."