Resource icon

xF1 Add-on 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
Josh
Size
6.4 KB
Extension
zip
Downloads
1
Views
1,245
First release
Last update

Similar resources

Generate a stack trace on slow queries
0.00 star(s) 0 ratings
Downloads
10
Updated
0.00 star(s) 0 ratings
Downloads
31
Updated
Allows the moderators to moderate user titles for configurable usergroups
0.00 star(s) 0 ratings
Downloads
5
Updated
Admin Search User IP AnimeHaxor
Search by IP Address using the Admin Search
0.00 star(s) 0 ratings
Downloads
11
Updated
Ban User IPs AnimeHaxor
Allow ban all user IPs which user has used
0.00 star(s) 0 ratings
Downloads
15
Updated