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

Run query on user upgrade (code example) 1.x

No permission to download
You can edit the library/ExtendUserUpgrade/UserUpgradeModel.php file to set your own query or code to execute when a user pays for an upgrade. The file already includes a query that I used for the person I made this for:

Code:
<?php

class ExtendUserUpgrade_UserUpgradeModel extends XFCP_ExtendUserUpgrade_UserUpgradeModel
{
	public function upgradeUser($userId, array $upgrade, $allowInsertUnpurchasable = false, $endDate = null)
	{
		$retval = parent::upgradeUser($userId, $upgrade, $allowInsertUnpurchasable, $endDate);

		$db = XenForo_Application::get('db');

		$db->query("
			UPDATE iConomy
			SET Balance = Balance + 3000
			WHERE username = (
				SELECT username
				FROM xf_user
				WHERE user_id = " . $userId . "
			)
		");

		return $retval;
	}
}
But he ended up needing to connect to a second database to update user records for his minecraft server. Here is an example with a second database connection. $db is the database for XenForo. $mcdb is the database for his minecraft server. This allowed him to query both databases to update point values:

Code:
<?php

class ExtendUserUpgrade_UserUpgradeModel extends XFCP_ExtendUserUpgrade_UserUpgradeModel
{
	public function upgradeUser($userId, array $upgrade, $allowInsertUnpurchasable = false, $endDate = null)
	{
		$retval = parent::upgradeUser($userId, $upgrade, $allowInsertUnpurchasable, $endDate);

		$db = XenForo_Application::get('db');
		$mcdb = new Zend_Db_Adapter_Pdo_Mysql(array(
			'host'     => 'localhost',
			'username' => 'dbuser',
			'password' => 'dbpass',
			'dbname'   => 'dbname'
		));

		$username = $db->fetchOne("
			SELECT username
			FROM xf_user
			WHERE user_id = " . $userId . "
		");

		$mcdb->query("
			UPDATE iConomy
			SET Balance = Balance + 3000
			WHERE username = '" . addslashes($username) . "'
		");

		return $retval;
	}
}
Author
Jake Bunce
Downloads
93
First release
Last update
Rating
5.00 star(s) 1 ratings

More resources from Jake Bunce

Latest reviews

This is a little addon that is extremely powerful if used properly. As always, Jake is top notch in providing help as well as making thoughtful addons that extend the power of Xenforo platform.