We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37523
    • 141 Posts
    I currently have a site with 52 users which I need to update all of them with either of two new User Group's. Is there some sort of Batch tool that I could use for this?

    Is this something that could be done through phpMyAdmin.

    [*]MODX Version: 2.2.8
    [*]PHP Version:5.3.26
    [*]Database: MySQL 5.1.70-cll


    Thanks in advance.

    This question has been answered by BobRay. See the first response.

      Glyn Szasz
      Sydney, Australia

      Happy to help (when can) and happy to learn

      If you are a Sydney based MODX developer would love to hear from you. Please contact me.
    • discuss.answer
      • 3749
      • 24,544 Posts
      The easiest way for me is a custom snippet like this (assuming that you want to add every user on the site to the two groups):

      [[!AddUsersToGroups]]


      <?php
      /* AddUsersToGroups snippet */
      $userObjs = $modx->getCollection('modUser');
      $count = count($userObjs);
      foreach($userObject as $userObj) {
          $userObj->joinGroup('GroupOne');
          $userObj->joinGroup('GroupTwo');
      }
      
      return '<p>' . $count . " Users Updated";


      If you had a lot more users, I'd recommend using getIterator() instead of getCollection().
        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
        • 37523
        • 141 Posts
        Thank you, Bob that does the trick
          Glyn Szasz
          Sydney, Australia

          Happy to help (when can) and happy to learn

          If you are a Sydney based MODX developer would love to hear from you. Please contact me.