We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered Importing users

  • So I decided to just change the System Setting signupemail_message. It might be different if your site is liable to be sending email to new Manger users as well.

    And it turns out inserting Extended Fields attributes is a cinch, even if you've got container attributes:

        $fields = array();
        $fields['active'] = true;
        $fields['passwordgenmethod'] = 'g';
        $fields['passwordnotifymethod'] = 'e';
        $fields['email'] = $email; 
        $fields['username'] = $username;
        $fields['fullname'] = $fullname;
        $fields['extended']['container']['name'] = $value;
        $response = $modx->runProcessor('security/user/create', $fields);
    

      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
    • discuss.answer
      Got it! Extended Fields, groups and all!!!

      <?php
          $groups = array();
          $groups['Group1']['usergroup'] = '7'; // id of group
          $groups['Group1']['role'] = '1'; // id of role
          $groups['Group2']['usergroup'] = '8';
          $groups['Group2']['role'] = '1';
          $fields = array();
          $fields['active'] = true;
          $fields['passwordgenmethod'] = 'g'; // automatically generate password
          $fields['passwordnotifymethod'] = 'e'; // email user his login details
          $fields['email'] = $email; 
          $fields['username'] = $username;
          $fields['fullname'] = $fullname;
          $fields['extended']['container']['name'] = $value;
          $fields['groups'] = $groups;
          $response = $modx->runProcessor('security/user/create', $fields);
        }
      
        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
        • 44580
        • 189 Posts
        Excellent. That's going to go into my cookbook. Perhaps it should be in yours too Susan.
        • I added it to the rtfm http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/using-runprocessor

          I'm actually building a CSV user import package with a lot of options. It will be a snippet that can be put on an unpublished page with a link to it in the Manager menu. It will have a form to upload a file, specifying the fields and delimiters. On submission, the snippet will process the file, using PHP's SplFileObject. The POST values will be used to configure the setCsvControl object and used in a loop on the resulting array to create the variables to be used in the new user creation.

          I suppose eventually I'll make it into a CMP, but I'm not sure that it's worth the effort. [ed. note: sottwell last edited this post 9 years, 3 months ago.]
            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