$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();
$userUpgradeModel = XenForo_Model::create('XenForo_Model_UserUpgrade');
$userUpgradeModel->upgradeUser($userId, $userUpgradeRecord, true, $endDate);