0 Votes

Changes for page Script

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

From version 7.1
edited by Ryan C
on 2025/05/13 16:01
Change comment: There is no comment for this version
To version 6.1
edited by Ryan C
on 2025/05/12 23:40
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,41 +1,9 @@
1 -{{groovy}}
2 -import org.xwiki.model.reference.DocumentReference
1 +{{velocity}}
2 +#set($doc = $xwiki.getDocument("XWiki.XWikiGroups"))
3 +#set($class = $doc.xWikiClass)
4 +* Fields in XWikiGroups:
5 +#foreach ($field in $class.properties.entrySet())
6 + - **$field.key** (type: $field.value.class.simpleName)
7 +#end
8 +{{/velocity}}
3 3  
4 -def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup")
5 -def groupClassName = "XWiki.XWikiGroups"
6 -
7 -// 1. Ensure the group document exists
8 -def groupDocAPI = xwiki.getDocument(groupDocRef)
9 -def groupDoc = groupDocAPI.getDocument()
10 -
11 -if (groupDoc.isNew()) {
12 - def apiDoc = xwiki.getDocument(groupDoc.documentReference)
13 - xwiki.saveDocument(apiDoc, "Created XWikiAllGroup page")
14 - println "🆕 Created XWiki.XWikiAllGroup page"
15 -}
16 -
17 -// 2. Proceed as before
18 -def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'")
19 -def added = []
20 -
21 -allUsers.each { userDocName ->
22 - def alreadyMember = groupDoc.getXObjects(groupClassName)?.any {
23 - it?.getStringValue("member") == userDocName
24 - }
25 -
26 - if (!alreadyMember) {
27 - def newObj = groupDoc.newXObject(groupClassName)
28 - newObj.setStringValue("member", userDocName)
29 - added << userDocName
30 - }
31 -}
32 -
33 -if (added) {
34 - def wrappedDoc = xwiki.getDocument(groupDoc.documentReference)
35 - xwiki.saveDocument(wrappedDoc, "✅ Added users to XWikiAllGroup: ${added.join(', ')}")
36 - println "✅ Added users to main wiki: ${added.join(', ')}"
37 -} else {
38 - println "✅ All users are already members of the main wiki."
39 -}
40 -{{/groovy}}
41 -