We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42562
    • 1,145 Posts
    Hello good people,

    I wish to transfer a great number of users (all users) to a new usergroup, at least drag and drop, something!

    I hoped and prayed there would be some batch management of users in MODx Revo 2.2.6. I can't find it anywhere.
    We had to move more than 500 users (with their profile info) from another CMS into Revo, the only way I found suitable for this particular job was via MYSQL. I succeeded, but alas, the members belong to no usergroup.

    I tried setting the number of the desired "member_group" field found in the _users table, no show. In fact, it's the only thing not working, I guess because MODx does not like you to do stuff directly in the DB.
    Username, user attributes (even extended) all of them work except for usergroup.

    How do you manage this? Has any kind person found a solution?

    Thanks in advance.


    This question has been answered by multiple community members. See the first response.

      TinymceWrapper: Complete back/frontend content solution.
      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
    • discuss.answer
      • 4172
      • 5,888 Posts
      You can try this.
      Create a new snippet 'joinUsersToGroup':

      <?php
      //[[!joinUsersToGroup? &group=`yourNewGroup`]]
      
      if ($collection = $modx->getCollection('modUser')){
          foreach ($collection as $user){
              $user->joingroup($group,'Member');
          } 
      }


      put this snippet-tag into a (unpublished) resource:
      [[!joinUsersToGroup? &group=`yourNewGroup`]]


      View your new created Resource.
      May be you will need to flush Permissions.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        We need a Batcher for users!
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 3749
          • 24,544 Posts
          FYI, the reason your method didn't work is that that information is in the modUserGroupMember object, which is the modx_member_groups table. You could have set the ID of the User Group in the user_group field. You would probably also want to set the role ID in the role field.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 42562
            • 1,145 Posts
            Many thanks, Bruno. It worked as expected, like Brazilian chicken broth. Thanks and much thanks.

            Could this code be tweaked to move users from one usergroup to another usergroup?

            @Susan Yes, we really need one... even if it's like the Resource groups management, drag and drop.
            I tried dragging a usergroup into another usergroup in the Access Controls - I was dreaming that permissions would be inherited...turns out the outcome was pretty useless, a mere "for organizational purposes"

            @BobRay Yes, I got my fair share of frustration finding it (or not finding it); thanks for the info... curious how MODx has users' info placed in various tables..._users, _attributes and so on... some tough luck trying to manually do stuff via phpMyAdmin. How then are the two tables related? Do you know which column in the _member_groups table uniquely identifies a user?

            Thanks everybody.
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • discuss.answer
              • 3749
              • 24,544 Posts
              Bob's Guides is your friend here: http://bobsguides.com/modx-object-quick-reference.html#modUserGroupMember.

              It lists all fields and the table name for virtually every MODX object. The aliases will tell you how any object is related to other objects and will advise you on using the relationships in code.

              The page is autogenerated by a fabulously ingenious snippet (if I do say so myself) that parses the MODX schema file.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 42562
                • 1,145 Posts
                Thanks. Excellent resource. One day I will be that enlightened.
                So I read and understood somethings and came with:
                <?php
                if ($collection = $modx->getCollection('modUser',$newGroup)){
                    foreach ($collection as $user){
                        $user->joingroup($oldGroup,'Member');
                    } 
                }

                Called like so
                [[!joinUsersToGroup? &oldGroup=`myOldMember-Group` &newGroup=`myNewMember-Group`]]

                I checked for errors; seems to be abundantly satisfactory, unless I missed something.
                Thank you very much Bruno17 and BobRay
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.