We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Ok, I've hacked in over 11,000 users from Evo into Revo, users and user_attributes. Now I'm trying to get the WebLoginPE extended fields into Revo's Profile extended fields. I've installed the web_user_attributes_extended table into my Revo database, so I can do like so:
    $stmt= $modx->query("SELECT * FROM `cms_web_user_attributes_extended`");
    if ($stmt) {
          // loop through the result set and inspect one row at a time
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo $row['internal_key']; // works fine
        }
    }

    Now I had thought to use this loop to load up a user object, get its profile, and use the API to load the four extended fields into the Profile extended field:
        $user = $modx->getObject('modUser', array('id'=>$row['internalKey']));
        $profile = $user->getOne('Profile');
        $fields = $profile->get('extended');
        $fields['company'] = $row['company'];
        $fields['serial'] = $row['serial'];
        $fields['techsupport'] = $row['techsupport'];
        $fields['reseller'] = $row['reseller'];
        $fields['contract'] = $row['contract'];
        $profile->set('extended',$fields);
        $profile->save();

    This works for the first user, then chokes with the PHP error "...Call to a member function getOne() on a non-object...".

    So how can I load the Profile extended field with the four relevant fields from my web_user_attributes_extended table?
      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
      • 4172
      • 5,888 Posts
      echo $row['internal_key']; 
      
      //vs
      
      array('id'=>$row['internalKey'])


      and I'm checking allways, if not false was returned:

      if ($user = $modx->getObject('modUser', array('id' => $row['internal_key']))) {
      
          if ($profile = $user->getOne('Profile')) {
              $fields = $profile->get('extended');
              $fields['company'] = $row['company'];
              $fields['serial'] = $row['serial'];
              $fields['techsupport'] = $row['techsupport'];
              $fields['reseller'] = $row['reseller'];
              $fields['contract'] = $row['contract'];
              $profile->set('extended', $fields);
              $profile->save();
          }
      
      }
      
      


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Well, I hacked the database manually by running a query against the attributes_extended table and forming the JSON string for each row, saving to a .sql file, then directly updating the user_attributes table to add the JSON string via phpMyAdmin Import of the file. Not pretty, but this is a one-time process.

        Now I need to figure out how to add users to a group in bulk. Not going to add 11,000 users to the group manually!
          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
          • 4172
          • 5,888 Posts
          $user->joinGroup('UserGroupNameOrId','OptionalRoleNameOrId');
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Yes, I'm trying to figure out how to get all the user objects. getIterator, I think...
              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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Ok, that part was easy:
              $users = $modx->getIterator('modUser');
              
              foreach($users as $user) {
                  $user->joinGroup(4);
              }
              
                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