XF 2.3 Looking for a way to sync secondary group memberships to a custom field

christisking

New member
Hello,

I hope this is an appropriate place to ask this question. If not, please feel free to move it. Thank you.

As the title says, I would like to be able to sync a users secondary group memberships to a custom field and so far I have not found a way to do that without custom development.

Currently I have some promotions that add users to a secondary group based on a custom field. However, let's say they were in 'A' and now are in 'B'. The promotion will add them to B, but they'll also still be in A.

So I want to be able to remove 'A' either as part of the promotion process, or as a follow up process. This is important because being in group A or B determines various things like permissions & access to various parts of out forums, as well as badges on their profile, etc.

Does anyone know of an easy way to accomplish this? Or even an add-on that would do it? I tried to create my own add-on but I'm not quite a skilled developer and so I was not able to make it function correctly.

Sincere thanks for any help.
 
Thank you for the response @Paul B :)


We are doing that already for some of the promotions, however that doesn't address the issue.

Our custom field has A/B options.

User picks custom field option A upon registration, as is assigned to group A via a group promotion.

At some point they decide to change to custom field option B.

Group promotion sees that they are now custom field B and adds them to group B.

Unfortunately they are also still in group A as well, so now they are in both groups A and B.

I want to then remove them from group A but I don't know of a simple way to do that, other than manually.

If you are suggesting NOT adding them to group B, if they are already in A, that also doesn't solve the issue.

The promotions are doing their job, but we lack a way to do the housekeeping after the fact, to prevent multiple group assignments.

And in reality there are dozens of options for the custom field. I only said A/B to keep things simple here.

If I was writing a SQL query for this, I'd say something like:

Add user to secondary group G according to their custom field selection
Then if user is in groups A-F or H-M, remove those, but don't touch groups N-Z (we don't want to remove ALL other groups, just certain ones that are relevant to the custom field options)

Ideally we could define this in the group promotion by selecting any groups we want to remove them from as part of the promotion
 
Last edited:
I want to then remove them from group A but I don't know of a simple way to do that

My comment above still stands.

The user group promotion system can automatically remove from user groups if they are a member of another user group.

Promotion A - add to user group A if not a member of user group B
Promotion B - add to user group B
 
My comment above still stands.

The user group promotion system can automatically remove from user groups if they are a member of another user group.

Promotion A - add to user group A if not a member of user group B
Promotion B - add to user group B
Okay, I must not be understanding how that works fully. I'l go back and look at it again. Thank you. (y)
 
Are you saying the 'user is NOT a member of these groups' option actually means 'remove user from these groups' upon promotion?

I was thinking it meant, only run the promtion if they aren't a member of these groups.
 
I just tried to follow your instructions as closely as possible, here is what happens:

Created two groups, test1 and test2.

Added test user into group test2 only.

Created promotion test1: Add user to group 'test1' if NOT a member of group 'test2' (and matches custom field option)

Enabled and clicked run now button.

Clicked manage promoted users button, clicked search button (search promotion history).

Watched and waited, refreshed repeatedly, the test1 promotion never ran (and I think it shouldn't because i told it don't run if member of group test2).

User was still only a member of group test2.

Then I went to the manually promote user dialog, selected the test user, selected promotion test1, clicked promote this user, clicked save button.

Now the promotion ran manually and the user is now in both groups test1 and test2.

I think this follows your instructions and reproduces my issues, the user is now in 2 groups instead of 1.
 
The system functions exactly as I have explained - that is the whole point of it.
It automatically promotes and demotes when the conditions are met, or not met.

If you are manually promoting and demoting members then they won't automatically be promoted and demoted.
 
I attempted to implement these changes and something went wrong. 500+ users ended up missing group memberships. I had to manually identify and fix everything via SQL statements (I have backups too, if needed).

It's now clear to me that:

1. The XenForo group promotion system is very powerful and can do a lot more than I realized
2. I don't know what I am doing and need to learn more before I play around with it on a live site

I'll go read some documentation and consult w/ ChatGPT and do some tests before going any further. I will report back later with results when I am ready to try again.

Thank you for your help and patience @Paul B
 
Note that promotions are only applied via cron to recently active members, or it will be applied the next time they log in.

To manually apply it to all members, regardless when they were last active, run the Rebuild user group promotions task in the Rebuild caches menu.
 
Back
Top Bottom