XF 2.1 Insert user data to a new table on User Upgrade


Hi everyone,

First of I'm coming from phpBB where I do have some custom work done but for some reason I am looking at the XF2 build an addon example and I'm very confused.

What I am trying to do with Xenforo is when someone purchases a user upgrade I would like to write to a separate table that user information. Like username, name, user upgrade title he just purchased etc.... If per example we refund that person or remove his user upgrade it would remove the user from that table.

On phpBB, we have a custom php form where people sign up and it automatically write to the database and then I display the results but we had to manually validate if the user had paid or not. So main reason upgrading to xenforo was that user upgrade ability but I'm looking for some help to get started.

Should I just find how and where the user upgrade writes to the DB and hard code directly there but I guess any update will break my code and I'll need to redo it everytime. Is this something that needs an addon to issues with updates.

Is this something too complicated to do and is there a simple existing addon that looks similar to this that I could look at the code.

Any help will be appreciated to get me started.
Last edited:
I was able to do what I wanted to insert into my own table by extending UserUpgrade

But now I would like to delete that row when a user is downgraded by looking at the user_upgrade_record_id that I also store in my table.

I'm trying to get the user_upgrade_record_id from:

public function actionDowngrade()
        $activeUpgrade = $this->assertRecordExists(
            'XF:UserUpgradeActive', $this->filter('user_upgrade_record_id', 'uint'), ['Upgrade', 'User']

        if ($this->isPost())
            /** @var \XF\Service\User\Downgrade $downgradeService */
            $downgradeService = $this->service('XF:User\Downgrade', $activeUpgrade->Upgrade, $activeUpgrade->User);

            return $this->redirect($this->buildLink('user-upgrades/active'));
            $viewParams = [
                'activeUpgrade' => $activeUpgrade
            return $this->view('XF:UserUpgrade\Downgrade', 'user_upgrade_active_downgrade', $viewParams);

So I'm trying with $activeUpgrade->Upgrade but this variable isn't declared. I tried bunch of stuff and can't get it.

Any hints or tips ?
Got everything working finally for my needs.

Basically we are racing league community and I needed to track userupgrades into a seperate table since I am using that information to know who will be racing in each series.

For anyone looking to do something similar here's what I use to extend the User Upgrades:

I don't know if we are allowed to extend from Service and Repository but it's what I used to achieve the desired result. Maybe some experienced addon Devs or @Chris D can validate this info to make sure its proper usage.
Top Bottom