• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 Manuelly upgrade a user (user upgrades) threw Xenforo API ?


I am currently working on my own payment gate for Xenforo which can process Coinpayments transactions.
The thing is I am nearly done, I was rebuilding the manuel user upgrade routine and then I found this doc online : http://fabrikar.com/forums/docs/classes/XenForo_Model_UserUpgrade.html

There I found this methode :
Upgrades the user with the speciUfied upgrade.

upgradeUser(integer $userId, array $upgrade, boolean $allowInsertUnpurchasable, integer | null $endDate) : integer | false
Is this the methode Xenforo calls when I manuelly upgrade a user there ?
Users->User Upgrades->Manually Upgrade User
XenForo_ControllerAdmin_UserUpgrade::actionManual; XenForo_ViewAdmin_UserUpgrade_Manual
If so how I can acces this class in my own php, which is a standalone file ( not an xenforo addon )

Regards Artur

Chris D

XenForo developer
Staff member
The first thing you need is to initialise the XF framework which needs these lines of code:
$startTime = microtime(true);
$fileDir = '/path/to/xenforo/root';

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$dependencies = new XenForo_Dependencies_Public();
That will give you access to pretty much everything in the XF framework.

So then you can instantiate the user upgrade model class and run the upgrade. You need to pass in the user's ID, the user upgrade record you are upgrading them to and the end date (which you can omit and it will just upgrade based on the length defined in the upgrade record). The true below will override any restrictions so that if the user upgrade is not purchasable for any reason then true will skip that restriction. It defaults to false so you can probably omit that too:
$userUpgradeModel = XenForo_Model::create('XenForo_Model_UserUpgrade');
$userUpgradeModel->upgradeUser($userId, $userUpgradeRecord, true, $endDate);
Thanks it works perfectly.
I just saw you are creating an instance of the upgrade model. I saw there is also an function to get it from the cache. Are there any benefits getting it from the cache?

Regards Artur

Chris D

XenForo developer
Staff member
The "cache" description there is a bit of a misnomer. It only caches it for the current request so in most contexts there is very little benefit. Just ignore it :)