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

Artur1339

Member
Hey,

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 :
Code:
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 ?
Code:
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
 
The first thing you need is to initialise the XF framework which needs these lines of code:
PHP:
$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();
$dependencies->preLoadData();
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:
PHP:
$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
 
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 :)
 
Alright, I moved to xf from vbulletin and I am glad. The support is amazing. Thanks for your fast response. I wish you a good weekend.
 
The first thing you need is to initialise the XF framework which needs these lines of code:
PHP:
$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();
$dependencies->preLoadData();
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:
PHP:
$userUpgradeModel = XenForo_Model::create('XenForo_Model_UserUpgrade');
$userUpgradeModel->upgradeUser($userId, $userUpgradeRecord, true, $endDate);
if im writing a custom php file how would I get $userUpgradeRecord? the userupgrade ID doesn't work it needs to be an array
 
Top Bottom