XF 2.2 Help me fix a mess with user groups (primary and additional)

sandnes

Member
I need to solve a problem and am hoping for some help here...
A1. My forum has a 1-year-duration user upgrade for people who donate, and triggering the upgrade adds them to a special 'additional user group' as you would expect, and it removes them from the additional user group upon expiration, also as you would expect. So far, so good.
A2. I have a few things programmatically tied to the user's primary user group. So, what I need is an action or task that can ALSO, when members upgrade, change their primary user group. Also to change it back when the upgrade expires.

That's my main issue. If anyone can help me with a couple of one-time SQL queries as described below, that would be great too. It's related...

B1. I want to execute a query that will sync all my members' user groups, because I've been changing them manually and they don't get reset that way.
Something like this: if a member is has group 12 as an additional user group, AND their primary user group is group 2 (only), change their primary user group to 12. (The AND is important.)
B2. Also need an SQL query for basically the opposite: if a member's primary user group is 12 but they don't have 12 as an additional user group, then change their primary user group to 2.

I'm not good with SQL which is why I need assistance with these.

Thank you...
 
Ooops ok I see that I can probably do my B1/B2 using batch user updates. Thank you for that.

But A2, is there a way to do that?
Add a secondary group on the user upgrade page and there's options to revert there if I recall correctly. Meaning when expired, the group added with be redacted.
 
That already works (see my A1). I need their PRIMARY user group to change automatically as well (and revert too).

(All answers have helped me so far, thank you all)
 
You really don't want their primary usergroup to change at all. Primary usergroup should be set to registered permanently, any added permissions should be used as secondary usergroup.
 
You really don't want their primary usergroup to change at all. Primary usergroup should be set to registered permanently, any added permissions should be used as secondary usergroup.
100 percent. The primary user group should always be Registered. Then secondary groups added.
Any user account on your forum is, by definition, a registered member and as such should belong to the Registered group
 
I could never get this to work - it seems to ignore the secondary_group_ids part, and only finds the user_group_id:
Code:
            <div class="message-avatar-wrapper">
            <xf:if is="in_array({$user.secondary_group_ids}, [3,4,5,12,17,19,20,31,32,33,36])">
                <xf:avatar user="$user" size="l" defaultname="{$fallbackName}" itemprop="image" />
            <xf:elseif is="in_array({$user.user_group_id}, [3,4,5,12,17,19,20,31,32,33,36])" />
                <xf:avatar user="$user" size="l" defaultname="{$fallbackName}" itemprop="image" />
            <xf:else />
                <xf:avatar user="$user" size="m" defaultname="{$fallbackName}" itemprop="image" />
            </xf:if>
If I can get this code to work - to find the value "12" (or any of the other ones I list) within the user's secondary group IDs - I can stop changing the primary user group. Any keen eyes pinpoint a fix?
 
No, I'm not checking the visitor's group, I'm checking the group of the member whose post is being written to the screen. This is part of message_macros template. It works with the elseif clause (which checks user group) but not with the first clause.
 
I got it all working now by a series of batch updates, and then fixing the code by changing the array check to
Code:
            <xf:if is="({$user.isMemberOf(12) })">
                <xf:avatar user="$user" size="l" defaultname="{$fallbackName}" itemprop="image" />

So thank you to everyone who replied, it ALL helped in some way.
 
Back
Top Bottom