Resource icon

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

No permission to download
Jake,
1) How can I create a sql query to send an alert/PM to a member with some title, body when an upgrade happens?
2) How can trigger XenForo_Model_User::addUserGroupChange() inside this code? I have some cache rebuild that will happen when this event is triggered so I like to trigger them via this code instead of rebuild manually.

Thanks a lot.
 
Jake,
1) How can I create a sql query to send an alert/PM to a member with some title, body when an upgrade happens?
2) How can trigger XenForo_Model_User::addUserGroupChange() inside this code? I have some cache rebuild that will happen when this event is triggered so I like to trigger them via this code instead of rebuild manually.

Thanks a lot.

1) You should use the datawriter for that. See this function for a code example using the datawriter:

XenForo_ControllerPublic_Conversation::actionInsert

2) User upgrade already have that functionality. You can specify additional groups when adding / editing an upgrade in the control panel.
 
Jake,
1) Somehow, this addon does not show any version number in the list of installed addons.
2) Can this be used when we downgrade the user?
 
Very nice, I've been looking for options for the upgrade system already available for xenforo rather than 'purchasing' additional addons.
What I'm also looking for is a query to get all users who purchased an upgrade with their Title (User Title Override) name and amount;
[Rank] PlayerName - $50.00

I'd like to show this in the forum sidepanel, preferably, if possible, the last 5 with a link to a page that shows all.
 
Very nice, I've been looking for options for the upgrade system already available for xenforo rather than 'purchasing' additional addons.
What I'm also looking for is a query to get all users who purchased an upgrade with their Title (User Title Override) name and amount;
[Rank] PlayerName - $50.00

I'd like to show this in the forum sidepanel, preferably, if possible, the last 5 with a link to a page that shows all.

That requires a separate addon and custom programming. You can post a request:

http://xenforo.com/community/forums/custom-service-development-requests.69/
 
Hey Jake, question:

Could you give a shell of how to use this to send an rcon command to a gameserver? Would require including steam-condenser.php, then sending the command.

Not even remotely sure where to start with that, even with the examples given.
 
I upgraded to latest 1.4.2, now i get this error:

Code:
Declaration of SlotUserUpgrade_UserUpgradeModel::downgradeUserUpgrades() should be compatible with XenForo_Model_UserUpgrade::downgradeUserUpgrades(array $upgrades, $sendAlert = true)

XenForo_Application::handlePhpError() in XenForo/Autoloader.php at line 119
XenForo_Autoloader::autoload() in XenForo/Autoloader.php at line 119
XenForo_Autoloader->autoload() in XenForo/Application.php at line 1039
XenForo_Application::autoload() in XenForo/Application.php at line 521
XenForo_Application::resolveDynamicClass() in XenForo/Model.php at line 189
XenForo_Model::create() in XenForo/Controller.php at line 101
XenForo_Controller->getModelFromCache() in XenForo/ControllerAdmin/UserUpgrade.php at line 563
XenForo_ControllerAdmin_UserUpgrade->_getUserUpgradeModel() in XenForo/ControllerAdmin/UserUpgrade.php at line 22
XenForo_ControllerAdmin_UserUpgrade->actionIndex() in XenForo/FrontController.php at line 347
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
XenForo_FrontController->run() in /home/nbfc/public_html/admin.php at line 13

Any ideas how to fix this @Jake Bunce ? :)
 
I upgraded to latest 1.4.2, now i get this error:

Code:
Declaration of SlotUserUpgrade_UserUpgradeModel::downgradeUserUpgrades() should be compatible with XenForo_Model_UserUpgrade::downgradeUserUpgrades(array $upgrades, $sendAlert = true)

XenForo_Application::handlePhpError() in XenForo/Autoloader.php at line 119
XenForo_Autoloader::autoload() in XenForo/Autoloader.php at line 119
XenForo_Autoloader->autoload() in XenForo/Application.php at line 1039
XenForo_Application::autoload() in XenForo/Application.php at line 521
XenForo_Application::resolveDynamicClass() in XenForo/Model.php at line 189
XenForo_Model::create() in XenForo/Controller.php at line 101
XenForo_Controller->getModelFromCache() in XenForo/ControllerAdmin/UserUpgrade.php at line 563
XenForo_ControllerAdmin_UserUpgrade->_getUserUpgradeModel() in XenForo/ControllerAdmin/UserUpgrade.php at line 22
XenForo_ControllerAdmin_UserUpgrade->actionIndex() in XenForo/FrontController.php at line 347
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
XenForo_FrontController->run() in /home/nbfc/public_html/admin.php at line 13

Any ideas how to fix this @Jake Bunce ? :)

Your function needs to have the same signature as the parent XenForo_Model_UserUpgrade::downgradeUserUpgrades. This is the signature:

Code:
public function downgradeUserUpgrades(array $upgrades, $sendAlert = true)
 
Your function needs to have the same signature as the parent XenForo_Model_UserUpgrade::downgradeUserUpgrades. This is the signature:

Code:
public function downgradeUserUpgrades(array $upgrades, $sendAlert = true)
Thank you, that works! :)

Do you know why the dates are zero for the added members?
vOUOmmi.png


Look at the last entry...

Here's the code:
*deleted
 
Last edited:
Thank you, that works! :)

Do you know why the dates are zero for the added members?
vOUOmmi.png


Look at the last entry...

Here's the code:
PHP:
<?php

class SlotUserUpgrade_UserUpgradeModel extends XFCP_SlotUserUpgrade_UserUpgradeModel
{
    public function upgradeUser($userId, array $upgrade, $allowInsertUnpurchasable = false, $endDate = null)
    {
        $retval = parent::upgradeUser($userId, $upgrade, $allowInsertUnpurchasable, $endDate);
       
        $options = XenForo_Application::get('options');
       
        // before we begin, lets check if the upgrade is allowed a slot on a server
        if(!in_array($upgrade['user_upgrade_id'], $options->slotuserupgrade_checkedupgrades))
        {
            return;
        }
       
        $user = $this->getModelFromCache('XenForo_Model_User')->getFullUserById($userId);
        $user['customFields'] = (!empty($user['custom_fields']) ? @unserialize($user['custom_fields']) : array());
       
        try
        {
            $slotdb = new Zend_Db_Adapter_Pdo_Mysql(array(
                'host'     => $options->slotuserupgrade_host,
                'username' => $options->slotuserupgrade_username,
                'password' => $options->slotuserupgrade_password,
                'dbname'   => $options->slotuserupgrade_dbname
            ));
           
            $slotdb->getConnection();
        }
        catch (Exception $e)
        {
            // error must have happened, lets log this to XenForo
            XenForo_Error::logException($e, false);
        }
       
        $field = (!empty($user['customFields']['originid']) ? $user['customFields']['originid'] : $user['username']);
        try
        {
            $field = $slotdb->select()->from(array('playerdata' => 'tbl_playerdata'), array('PlayerID'))->where('SoldierName = ?', $field);
            $field = $slotdb->fetchAll($field);
           
            $field = (!empty($field[0]['PlayerID']) ? (int)$field[0]['PlayerID'] : (string)$user['username']);
           
            if(ctype_digit($field)) {
                $data = array('player_group' => 'slot_reserved', 'player_id'  =>  $field);
            } else {
                $data = array('player_group' => 'slot_reserved', 'player_identifier'  =>  $field);
            }
           
            $slotdb->insert('adkats_specialplayers', $data);
        }
        catch (Exception $e)
        {
            // error must have happened, lets log this to XenForo
            XenForo_Error::logException($e, false);
        }
       
        return $retval;
    }
   
    public function downgradeUserUpgrades(array $upgrades, $sendAlert = true)
    {
        if (!$upgrades)
        {
            return;
        }
       
        $retval = parent::downgradeUserUpgrades($upgrades);
       
        $options = XenForo_Application::get('options');

        try
        {
            $slotdb = new Zend_Db_Adapter_Pdo_Mysql(array(
                'host'     => $options->slotuserupgrade_host,
                'username' => $options->slotuserupgrade_username,
                'password' => $options->slotuserupgrade_password,
                'dbname'   => $options->slotuserupgrade_dbname
            ));
           
            $slotdb->getConnection();
        }
        catch (Exception $e)
        {
            // error must have happened, lets log this to XenForo
            XenForo_Error::logException($e, false);
        }
       
        $playerRecors = array();

        foreach ($upgrades AS $upgrade)
        {
            if(!in_array($upgrade['user_upgrade_id'], $options->slotuserupgrade_checkedupgrades))
            {
                continue;
            }
       
            $user = $this->getModelFromCache('XenForo_Model_User')->getFullUserById($upgrade['user_id']);
            $user['customFields'] = (!empty($user['custom_fields']) ? @unserialize($user['custom_fields']) : array());
            $field = (!empty($user['customFields']['originid']) ? $user['customFields']['originid'] : $user['username']);
           
            try
            {
                $field = $slotdb->select()->from(array('playerdata' => 'tbl_playerdata'), array('PlayerID'))->where('SoldierName = ?', $field);
                $field = $slotdb->fetchAll($field);
               
                $field = (!empty($field[0]['PlayerID']) ? (int)$field[0]['PlayerID'] : (string)$user['username']);
               
                if(ctype_digit($field)) {
                    $data = array('player_id' => $field);
                } else {
                    $data = array('player_identifier'  =>  $field);
                }
                $playerRecors[] = $data;
               
            }
            catch (Exception $e)
            {
                // error must have happened, lets log this to XenForo
                XenForo_Error::logException($e, false);
            }
           
            $slotdb->delete('adkats_specialplayers', 'player_id IN (' . $slotdb->quote($playerRecors) . ') OR player_identifier IN (' . $slotdb->quote($playerRecors) . ')');
        }

        return $retval;
       
    }
}

Where is your insert or update query? You would have to debug the date you are writing to the database to make sure it's not empty.
 
I am trying to get the "created" and "enddate" inserted into the db to the "player_effective" and "player_expiration"

6iKFadh.png

Where is your insert or update query? You would have to debug the date you are writing to the database to make sure it's not empty.
I just have insert and delete, i'm not the one who made this script, so i have no idea how to do this, but the script that i am using this with has added the dates part to it, and it's not working anymore when the dates are zero.

So i was hoping you could help me. :)
 
I am trying to get the "created" and "enddate" inserted into the db to the "player_effective" and "player_expiration"

6iKFadh.png


I just have insert and delete, i'm not the one who made this script, so i have no idea how to do this, but the script that i am using this with has added the dates part to it, and it's not working anymore when the dates are zero.

So i was hoping you could help me. :)

This requires debugging your code (or their code). Ideally you should contact the author of the code.
 
@Jake Bunce
Upgraded to XF 1.4.3 this morning and now I got several errors on ACP

Code:
ErrorException: Declaration of ExtendUserUpgrade_UserUpgradeModel::downgradeUserUpgrades() should be compatible with XenForo_Model_UserUpgrade::downgradeUserUpgrades(array $upgrades, $sendAlert = true) -library/ExtendUserUpgrade/UserUpgradeModel.php:0
Generated By: Unknown Account, Today at 1:50 PM
Stack Trace
#0 /home/nginx/domains/quantnet.com/public/library/XenForo/Autoloader.php(119): XenForo_Application::handlePhpError(2048, 'Declaration of ...', '/home/nginx/dom...', 0, Array)
#1 /home/nginx/domains/quantnet.com/public/library/XenForo/Autoloader.php(119): XenForo_Autoloader::autoload()
#2 /home/nginx/domains/quantnet.com/public/library/XenForo/Application.php(1047): XenForo_Autoloader->autoload('ExtendUserUpgra...')
#3 /home/nginx/domains/quantnet.com/public/library/XenForo/Application.php(529): XenForo_Application::autoload('ExtendUserUpgra...')
#4 /home/nginx/domains/quantnet.com/public/library/XenForo/Model.php(189): XenForo_Application::resolveDynamicClass('XenForo_Model_U...', 'model')
#5 /home/nginx/domains/quantnet.com/public/library/XenForo/CronEntry/CleanUp.php(97): XenForo_Model::create('XenForo_Model_U...')
#6 [internal function]: XenForo_CronEntry_CleanUp::runUserDowngrade(Array)
#7 /home/nginx/domains/quantnet.com/public/library/XenForo/Model/Cron.php(356): call_user_func(Array, Array)
#8 /home/nginx/domains/quantnet.com/public/library/WhoHasReadAThread/Model/Cron.php(30): XenForo_Model_Cron->runEntry(Array)
#9 /home/nginx/domains/quantnet.com/public/library/XenForo/Deferred/Cron.php(24): WhoHasReadAThread_Model_Cron->runEntry(Array)
#10 /home/nginx/domains/quantnet.com/public/library/XenForo/Model/Deferred.php(256): XenForo_Deferred_Cron->execute(Array, Array, 7.9999949932098, '')
#11 /home/nginx/domains/quantnet.com/public/library/XenForo/Model/Deferred.php(390): XenForo_Model_Deferred->runDeferred(Array, 7.9999949932098, '', false)
#12 /home/nginx/domains/quantnet.com/public/library/XenForo/Model/Deferred.php(335): XenForo_Model_Deferred->_runInternal(Array, NULL, '', false)
#13 /home/nginx/domains/quantnet.com/public/deferred.php(23): XenForo_Model_Deferred->run(false)
#14 {main}
 
@Jake Bunce
I changed the signature of the function from
Code:
public function downgradeUserUpgrades(array $upgrades)
{
parent::downgradeUserUpgrades($upgrades);
to
Code:
public function downgradeUserUpgrades(array $upgrades, $sendAlert = true)
{
parent::downgradeUserUpgrades($upgrades, $sendAlert = true);

Not sure if this is the correct way to fix it.
 
Back
Top Bottom