XF 2.2 What is the best way to detect when a user gets or loses a group

I am currently trying to accomplish this by extending the UserGroupChange service, but either manually adding a user to the group via the edit user page does not trigger this or I am extending the wrong thing.
1636667082839.webp

PHP:
<?php

namespace Retro\Sourcebans\Service\User;

class UserGroupChange extends XFCP_UserGroupChange
{
    public function addUserGroupChange($userId, $key, $addGroups)
    {
        $this->app->logException(new \Exception(\XF::dumpSimple([$userId.$key, $addGroups])));
        \XF::dump([$userId, $key, $addGroups]);
        return false;
    }
}

Currently im just tring to make an error occur to show me im doing the right thing lol.

Any help would be greatly appreciated!
 
Most likely won't work this way, editing users in ACP doesn't use that service.

I'd use an event listener on entity_post_save for XF:User
PHP:
if ($entity->isChanged('user_group_id') || $entity->isChanged('secondary_group_ids'))
{
// do smth.
}
 
Top Bottom