humhub / rest

HumHub Rest API Module
24 stars 24 forks source link

Enhancement: Session - count online users #48

Open c-nv-s opened 3 years ago

c-nv-s commented 3 years ago

Is it possible to make a USER>SESSION endpoint to GET the members statistic - number of online users

https://github.com/humhub/humhub/blame/0086c52945f32f5b2dd86c17a194a9014238dc2a/protected/humhub/modules/directory/widgets/MemberStatistics.php#L27

At the moment there only appears to be an option to DELETE sessions: https://www.humhub.com/en/marketplace/rest/docs/html/user.html#tag/Session/paths/~1user~1session~1all~1{id}/delete

c-nv-s commented 3 years ago

I am currently also exploring any flexible, non-interactive ways of obtaining this value ( and any other useful values ) via the command line as well.

The https://docs.humhub.org/docs/admin/console/ commands are very useful, however I am not aware of a way to add a custom command outside of the base humhub installation, similar to the theming implementation.

I tried importing https://github.com/yiisoft/yii2-shell via composer to see if there is a non-interactive mode but this seems to downgrade and remove many essential humhub dependencies. Although the command did still seem to work in interactive mode

>>>  \humhub\modules\user\components\Session::getOnlineUsers()->count();
=> 1

I am guessing there should be a way to just run the command through vanilla psysh but then you'd have to import the yii2 framwork in the command too.

$ ./psysh --no-interactive ' include ... ; require ... ; \humhub\modules\user\components\Session::getOnlineUsers()->count(); '

Any help or advice for the best approach on this would be appreciated.

luke- commented 3 years ago

I think the REST API is the best way to do this. However, the endpoint for this is currently missing.