How to detect Member group change in SilverStripe 4

148 Views Asked by At

I have a DataExtension for Member, MyMemberExtension.

I'm trying to detect a user being moved from a pending-users group to a public-users group using onBeforeWrite and onAfterWrite in MyMemberExtension. However the group change seems to happen before the onBeforeWrite here.

In MyMemberExtension I added an $IsPending class member.

public function onBeforeWrite()
{
    if ($this->owner->inGroup('pending-users'))
    {
        self::$isPending = true;
    }
}

and

public function onAfterWrite()
{
    if ($this->owner->inGroup('public-users') and self::$isPending)
    {
        # Moved from the pending to public - send email
    }
}

I also tried using $this->owner->getChangedFields(); but Groups isn't part of the array.

How am I able to detect a user changing from pending-users to public-users?

0

There are 0 best solutions below