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

XF 1.1 User group change (secondary_groups) via SQL

Discussion in 'XenForo Questions and Support' started by fronix, Apr 27, 2012.

  1. fronix

    fronix Member

    Hi,

    I want to know what needs to be done to be able to add/remove a secondary_group to a user via SQL. I need it because we are using the XenForo forum to sync the users to our minecraft server. And we do not want to use callback to run a .php file on the webserver because of security and stability.

    Thanks
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This:

    http://xenforo.com/community/thread...-nodes-updating-usergroups.28811/#post-333967

    Rebuilding the cache is necessary to update the permissions of the user after changing their group with a query.

    However, you want to query the secondary groups which isn't so easy because the secondary groups are stored as a comma list. You would have to query the list and manipulate it using PHP code (explode on the comma, manage the array elements, implode using a comma, then set that value in the user record). Then you still need to rebuild the cache afterwards.
     
  3. fronix

    fronix Member

    Okay as I suspected then thank you again for the quick and perfect answer Jake!
     
  4. Zwirc

    Zwirc Member

    Hi! Did you find a solution?
     
  5. fronix

    fronix Member

    Hey,

    Well we couldn't find a good solution without having to call a .php script from the website so we made our own plugin to do just that. And then we just made a php file to update the users using $_GET with a key.

    I'll post our PHP code here if you want to use or get the basic idea, I'm presuming that you know all the necessary stuff about XenForo's system.

    PHP:
    <?php
    require_once('../../forum/library/XenForo/Autoloader.php');
    include(
    '../functions.php');
    XenForo_Autoloader::getInstance()->setupAutoloader('../../forum/library');
    XenForo_Application::initialize('../../forum/library''../../forum/');
    XenForo_Application::set('page_start_time'time());
    XenForo_Application::disablePhpErrorHandler();
    XenForo_Application::setDebugMode(false);

    $allowed_ip "1.1.1.1.1"//Make sure only the server can access this file

    if($_SERVER['REMOTE_ADDR'] == $allowed_ip){

    $key "somebigrandomkey";
    $groups = array(3,4,6,36); //The Secondary Groups you want to use
    $ranks = array(7,38,39,40); //The forum ranks you want to use

        
    if(isset($_GET['key']) == $key && $_GET['username'] && $_GET['rank']){
            
    $userName $_GET['username'];
            
    $userRank $_GET['rank'];

            
    $mu XenForo_Model::create('XenForo_Model_User');
            
    $user $mu->getUserByName($userName);
            
    $changeRank $session->promote_user($userName$userRank);

            if(
    $mu->getUserByName($userName) != false && is_numeric($userRank) == true){
                if(!
    in_array($user['secondary_group_ids'], $groups)){
                  if(
    $user['secondary_group_ids'] != $userRank){
                    if(
    $changeRank == 1){
                        echo 
    0;
                    }else{
                        echo 
    1;
                    }
                  }else{
                    echo 
    2;
                  }
                }else{
                    echo 
    3;
                }
            }else{
                echo 
    4;
            }
        }
    }else{
        
    //header('Location: http://www.google.com');
    }


    ?>
     

Share This Page