XF 1.5 Which database tables need to be altered to manually add/remove user from usergroup?

XFuser

Active member
Hello,

We want to do some simple customizations where we run some simple cron job queries daily to check things like messages per last 30 days, likes received per last 30 days, etc. and then give/remove privileges/permissions by adding/removing users to Usergroups based on those queries.

To add and remove a user from a Usergroup, will simply adding/removing the Usergroup ID to/from the secondary_group_ids column of the xf_user table be enough?

In other words, which database tables/columns need to be altered to manually add/remove a user from usergroup?

Thank you.
 

nocte

Well-known member
No, I would not change user groups via SQL. There's a lot of work involved on the PHP-side; e.g. permissions cache.

You could create an addon that adds some user criteria like "messages in the last 30 days" and use that for the XF core "user group promotions".

But AFAIK it would also remove the promotion (i.e. additional user group) once the minimal requirement is not met anymore (don't know if that is desired). You would also have to add a cronjob that updates additional xf_user columns like "messages in the last 30 days" (these values should be cached and not fetched dynamically).
 

XFuser

Active member
No, I would not change user groups via SQL. There's a lot of work involved on the PHP-side; e.g. permissions cache.
Thank you for letting us know.

You could create an addon
We have no experience creating Add-ons, so we prefer to avoid that solution.

Maybe use the API?
This seems a bit more straightforward.

So would it be as simple as running our SQL query and then adding/removing users from Usergroups by:

1. Getting list of users current secondary group IDs via Data Type: User and setting it into a temporary array in PHP
2. Updating that temporary array variable with the addition/removal of new Usergroup IDs
3. Setting Users secondary usergroup IDs via users/{id}/ -> secondary_group_ids using that temporary array?


Please confirm and thank you.
 
Top