// Set XenForo directory
$dir = '/var/www/public';
// Require XenForo
require($dir . '/src/XF.php');
// Load XenForo
XF::start($dir);
$app = XF::setupApp('XF\Pub\App');
// Get Upgrade Repository
$app->repository('XF:UserUpgrade');
// Get User Information
$userFinder = \XF::finder('XF:User');
$username = $userFinder->where('username', $subDetails['username'])->fetchOne();
// Get UserUpgrade Information
$upgradeFinder = \XF::finder('XF:UserUpgrade');
$userUpgrade = $upgradeFinder->where('user_upgrade_id', $upgradeId)->fetchOne();
// Get Active Upgrade Information
$userUpgradeActiveFinder = \XF::Finder('XF:UserUpgradeActive');
$activeUserUpgrades = $userUpgradeActiveFinder->where('user_id', $username->user_id)->fetch();
// Upgrade User
$upgradeService = $app->service('XF:User\Upgrade', $userUpgrade, $username);
$upgradeService->setEndDate($timestamp);
$upgradeService->ignoreUnpurchasable(true);
$upgradeService->upgrade();
// Downgrade User
$downgradeService = $app->service('XF:User\Downgrade', $userUpgrade, $username);
$downgradeService->setSendAlert(false);
$downgradeService->downgrade();
// - - - - - - - - - - - - - - - - - - -
// Extend User Upgrade
foreach ($activeUserUpgrades as &$activeUserUpgrade) {
if (in_array($activeUserUpgrade->user_upgrade_id, $validUpgrades)) {
$userUpgrade = $activeUserUpgrade->Upgrade;
$expireDate = $activeUserUpgrade->end_date;
break;
}
}
$upgradeService = $app->service('XF:User\Upgrade', $userUpgrade, $username);
$upgradeService->setEndDate($expiryDate + $monthInUnixtime /*FOR EXAMPLE*/);
$upgradeService->ignoreUnpurchasable(true);
$upgradeService->upgrade();