LucD
1
Hi XWiki Community,
I managed to have a counter of users with this velocity code:
$services.query.hql("select count(distinct obj.name) from BaseObject obj where obj.className = 'XWiki.XWikiUsers'").execute()[0]
Or this one:
$services.user.group.getMembers('xwiki:XWiki.XWikiAllGroup').size()
How can I adapt it to count only active users?
How is the “active” field named in the database?
Thank you in advance!
Luc
LucD
3
Hi @vmassol,
Thank you for your answer.
I tried to use this code to get the isActive
property:
#foreach ($userWiki in $services.user.group.getMembers('xwiki:XWiki.XWikiAllGroup'))
#set ($props = $services.user.getProperties($userWiki))
1. $userWiki, $props.getEmail(), $props.isActive()
#end
But it returns this content:
- xwiki:XWiki.a=aaa_mycompany=fr, L.DURON@mycompany.fr, true
- xwiki:XWiki.b=bbb_mycompany=fr, L.DURON@mycompany.fr, true
- xwiki:XWiki.c=ccc_mycompany=fr, L.DURON@mycompany.fr, true
- …
Why are the last two variables concerning my user and not the user of the loop?
Regards,
Luc
vmassol
4
1 Like
LucD
5
Thank you very much @vmassol for your explanations!
This code does the trick:
#set ($nbActiveUsers = 0)
#foreach ($userWiki in $services.user.group.getMembers('xwiki:XWiki.XWikiAllGroup'))
#set ($props = $services.user.getProperties($userWiki.toString()))
#if ($props.isActive())
#set ($nbActiveUsers = $nbActiveUsers + 1)
#end
#end
Or this query:
$services.query.xwql('where doc.object(XWiki.XWikiUsers).active = 1').addFilter('count').execute()[0]
Best regards,
Luc
Note that the query is much faster and lighter on CPU.
1 Like