Resource icon

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

No permission to download
  • Author Author Josh
  • Creation date Creation date
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,452
First release
Last update

Similar resources

731Threads
2,287Messages
63,785Members
admosLatest member
Back