XF 2.2 Demote users who haven't logged in for a period of time

tpmedia

Member
I guess I might not be able to find an answer to this because I don't know the correct terminology but I have done a lot of googling and couldn't find a solution.

We have a User Group promotion that adds users to a group after a number of days and a number of posts, for users who haven't logged in for a period of time, say 3 months, we would like to remove the promotion, i.e. remove the user from the group.

Any suggestions as to how I would do that?
 
Not by default as promotions only run for people active within the past 2 hours, logic being there wouldn't be any tangible benefit to applying (or removing) promotions if the user isn't online to benefit/notice.

To achieve it you'd need a new promotions cron that queries users last active 3 months ago instead of within the past 2 hours.
 
You can add them to a new group with this:

User has not visited for at least X days:

Obviously as soon as they log back in they would be removed from that group and still be in the other one, so this may work for you.
 
But they wouldn't get picked up for promotions to be put into that group in the first place unless they've been active recently.

Criteria like that only work if you're querying users and running the criteria against them, but they won't get picked up by the standard promotions cron because the activity cut off is 2 hours.
 
Sad Keanu Reeves GIF by Feliks Tomasz Konczakowski
 
The limitation with user criteria is that it doesn't directly query users based on criteria, you pass through users and it runs the criteria agaisnt them. So it's a chicken and egg situation, you want to find users that match the criteria but you don't know which ones match the criteria without having some users to check first. Or more, you need to select users that have at least a chance of matching the criteria, so if the criteria is "active more than 7 days ago" and it's only selecting users active within the last 2 hours, you will be guaranteed to have a 0% match rate.

For these time based ones to work, it would have to check the entire userbase every time the cron ran to find every user that might match the criteria, which wouldn't be performant. We've had similar issues with needing to find users active > 6 months ago or who have upgrades expiring soon, where the solution is just to specifically query those users directly, which just isn't how the criteria system works.
 
Last edited:
Apologies for not responding sooner, I've been away for a few days.

Sounds like it's not going to be easy to do. The specific situation is that we allow users to buy and sell on our forum if they meet certain criteria. That is done by promoting them to a group which then gives them access to the sales forum. I was hoping that for users who haven't logged on for 6 months we could revoke the group. Probably could do that with a cron job that runs in the middle of the night but I am far more familiar with SQL than with XF cron so I might just be tempted to do it directly in the database. I've looked at XF Cron and simply have no idea how to get started with that
 
So if they log in after 6 months you still don't want them in the group? Or they would be promoted back to it? In which case there would be no need for removal.
 
So if they log in after 6 months you still don't want them in the group? Or they would be promoted back to it? In which case there would be no need for removal.
You could still use criteria to revoke the group it will just apply if/when they log back in won't it?
This is essentially why there's no benefit to it checking promotions for users that haven't been active - there would be no difference to their experience if the promotion was removed as they're not online anyway, and if they came back online they a) wouldn't match the inactivity criteria to have the promotion removed and b) would match the criteria to be added back to the group.

The only benefit I can see to removing the promotion is if there was any sort of visual identifier of it like username styling or a badge.
 
So if they log in after 6 months you still don't want them in the group?
If they haven't logged in for 6 months they are removed from the group

You could still use criteria to revoke the group it will just apply if/when they log back in won't it?
This is essentially why there's no benefit to it checking promotions for users that haven't been active - there would be no difference to their experience if the promotion was removed as they're not online anyway, and if they came back online they a) wouldn't match the inactivity criteria to have the promotion removed and b) would match the criteria to be added back to the group.

The only benefit I can see to removing the promotion is if there was any sort of visual identifier of it like username styling or a badge.

We have had some old accounts suddenly log in out of the blue and try to trade so we suspect that some email/passwords have been hacked or leaked from some other site and then used to try to buy/sell on our site. When this has happened we have changed the passwords but restricting all old accounts would limit this activity
 
Okay, that's a slightly different issue then, I though it was something more specific to the benefits of being in the group they're promoted to.

We have an addon that will set users to have to either re-confirm their email address or reset their password (or both) after X days of inactivity. It's not generally available but if you are interested in that, open a ticket with us and I'll see if we can sort out a licence for it.
 
Top Bottom