XF 2.1 User Upgrade with MySQL Query

Jerr0w

Member
Hello,

I would like to upgrade users through MySQL queries. Can somebody tell me which MySQL queries I have to execute to perform it correctly?
 
We wouldn't recommend using queries - there is a lot of data to update.

Why can't you use the user group promotion system, or the manual promotion method in the ACP?
 
Is there no help for this?

It seems like that it's possible to do that through the XenForo Framework

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();

$userUpgradeModel = XenForo_Model::create('XenForo_Model_UserUpgrade');
$userUpgradeModel->upgradeUser($userId, $userUpgradeRecord, true, $endDate);

Is it possible to downgrade subscriptions as well? @Brogan
 
The code you posted is for XF1. There are services for upgrading and downgrading users in XF2 (\XF\Service\User\Upgrade and \XF\Service\User\Downgrade). You can reference \XF\Admin\Controller\UserUpgrade::actionManual() and \XF\Admin\Controller\UserUpgrade::actionDowngrade() to see how they are used.
 
The code you posted is for XF1. There are services for upgrading and downgrading users in XF2 (\XF\Service\User\Upgrade and \XF\Service\User\Downgrade). You can reference \XF\Admin\Controller\UserUpgrade::actionManual() and \XF\Admin\Controller\UserUpgrade::actionDowngrade() to see how they are used.

Thanks. Can you maybe tell me how I can load the XF Framework? Doesn't work as in XF 1.
 
Untested:

PHP:
<?php

$phpVersion = phpversion();
if (version_compare($phpVersion, '5.6.0', '<'))
{
	die("PHP 5.6.0 or newer is required. $phpVersion does not meet this requirement. Please ask your host to upgrade PHP.");
}

$dir = __DIR__;
require($dir . '/src/XF.php');

\XF::start($dir);
\XF::setupApp('XF\Pub\App');
 
Thank you! Will test it soon :)

Edit: Works perfectly!

One last question: Can you maybe give me the code for user upgrade/downgrade as well? :)
 
Last edited:
Top Bottom