We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    Thanks. My test was run on a local install (Vista, XAMPP, Evo 1.0.2) and I was executing the SQL commands from the phpMyadmin window/app. So what I posted did actually work. But adding the quotes might be the proper way?

    So that’s the good news - a batch creation of users can be done via imports into the right tables. For the record, here is what I did which worked on the test setup noted above (WebLoginPE had already been installed and run before, so the "extended" database existed) :

    - Created three CSV files which contained the info relevant to the three tables I wanted to edit : modx_web_users, modx_web_user_attributes and modx_web_user_attributes_extended. Here are sample entries from each of the CSV files, in their respective order :
    "id","username","password","cachepwd"
    1,"tempuser1","temp619415",
    2,"tempuser2","temp782623",
    

    "id","internalKey","fullname","role","email","phone","mobilephone","blocked","blockeduntil","blockedafter","logincount","lastlogin","thislogin","failedlogincount","sessionid","dob","gender","country","state","zip","fax","photo","comment"
    1,1,"Member 1",0,"[email protected]","888-555-1212",,0,0,0,0,0,0,0,,0,0,,"VT","12345",,,
    2,2,"Member 2, Inc.",0,"[email protected]","888-555-1212",,0,0,0,0,0,0,0,,0,0,,"VT","01234",,,
    

    "id","internalKey","physicaladdress","mailingaddress","mailingaddress2","city","contact","category1","category2","category3","web","description","notes","keymember","membership","logolink","videolink"
    1,1,"123 South Main St.","P.O. Box 123",,"Somewhere","Tom Smith","Service",,,"http://www.example1.com","Marketing and advertising to organizations. ",,0,1,,
    2,2,"123 North Main St.","P.O. Box 456",,"Anywhere","Harry Smith","Manufacturing",,,"http://www.example2.com","Manufacturer of metal products. ",,0,1,,
    


    NOTE : this install already had a webuser set up and their id was "1". So I ended up having the first two lines of the file (the header and the clashing user) ignored after I saw the the first attempt didn’t overwrite the existing entry. He could have been renumbered in the CSV though.

    For importing the first CSV file here was the SQL (executed from within phpmyadmin) :
    LOAD DATA LOCAL INFILE 'C:/local_folder/test_webusers.txt'
    INTO TABLE modx_web_users
    FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    IGNORE 2 LINES;
    

    Then I needed to apply the MD5 function to the password. Initally I did this
    UPDATE modx_web_users SET password = MD5( password );

    But that also messed up the already existing user. So I had to manually reset their password in phpmyadmin. I think I could have limited the SQL command by appending something like
    WHERE `modx_web_users`.`id` >1;
    

    For importing the second set of data :
    LOAD DATA LOCAL INFILE 'C:/local_folder/test_webusersattrib.txt'
    INTO TABLE modx_web_user_attributes
    FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    IGNORE 2 LINES;
    


    For the third set of data, the existing "extended" table had to be altered to have the custom fields I needed :
    ALTER TABLE `modx_web_user_attributes_extended`  ADD `physicaladdress` VARCHAR(255) NOT NULL,  ADD 
    `mailingaddress` VARCHAR(255) NOT NULL,  ADD `mailingaddress2` VARCHAR(255) NOT NULL,  ADD `city` VARCHAR
    (100) NOT NULL,  ADD `contact` VARCHAR(100) NOT NULL,  ADD `category1` VARCHAR(100) NOT NULL,  ADD 
    `category2` VARCHAR(100) NOT NULL,  ADD `category3` VARCHAR(100) NOT NULL,  ADD `web` VARCHAR(255) NOT NULL, 
     ADD `description` VARCHAR(1024) NOT NULL,  ADD `notes` VARCHAR(255) NOT NULL,  ADD `keymember` INT(1) NOT 
    NULL,  ADD `membership` INT(1) NOT NULL,  ADD `logolink` VARCHAR(255) NOT NULL,  ADD `videolink` VARCHAR
    (255) NOT NULL
    

    which then allowed this to work :
    LOAD DATA LOCAL INFILE 'C:/local_folder/test_webusersattribext.txt'
    INTO TABLE modx_web_user_attributes_extended
    FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    IGNORE 2 LINES;
    


    This all allowed me to successfully log in as tempuser2 with the above noted password. And if I had indexed the id keys properly so as to avoid the clash with the existing id, I’m sure I could have logged in as tempuser1 as well.

    The question now is this : are all these fields now available to WebLoginPE with only the addition of the custom fields parameter? In other words does it now know where to go and find all this info, allowing me to construct a form with fields from all three tables, without having to jump through more hoops?

    At least I hope this helps others wondering how to get a bunch of users loaded into the system. And thanks again for your help, Susan!

    MattC
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Ah, I’m sorry, I missed the context of your query. Since it’s a reference to the password field, then it certainly would not want to be in quotes.
        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
        • 1892
        • 82 Posts
        Quote from: mconsidine at Mar 18, 2010, 05:11 PM

        <snip>
        The question now is this : are all these fields now available to WebLoginPE with only the addition of the custom fields parameter? In other words does it now know where to go and find all this info, allowing me to construct a form with fields from all three tables, without having to jump through more hoops?

        At least I hope this helps others wondering how to get a bunch of users loaded into the system. And thanks again for your help, Susan!


        Many thanks for posting all this info. I have got more or less the exact same job to do for a club I’m involved in. I’ve been getting on with the easy stuff and putting this bit off, but this seems to be just what I was looking for.

        Thanks once again, I’m sure it will be a big help.
          • 18913
          • 654 Posts
          Glad this might be of some help.

          It also turns out I need to assign these folks to a webuser group. Soooo....

          In phpmyadmin :
          INSERT INTO modx_webgroup_names (name) VALUES ('test_user_group')


          This create a webuser group with an id of 1.

          Now,
          INSERT INTO modx_web_groups (webuser) SELECT (internalKey) FROM modx_web_user_attributes
          

          added entries with all the existing internal keys.
          Then,
          UPDATE modx_web_groups SET webgroup='1'
          

          assigned everyone to webgroup 1.

          There seems to me to be a lot of opportunity for things to go goofy if there are existing webusers and webgroups. The above only worked for me because I’m dealing with a clean install. In particular,
          - it would be nice to see what the commands should look like if any clashes were to be overwritten with new data
          - ideally, the last two SQL calls above should be able to be combined into one call that uses info in a
          CSV file. Or at the very least allows for the matching to a webgroup based on a webgroup name (rather than having to figure out ahead of time what the number is).

          But for a one-shot-deal to get something set up, this seems to be working on my test bed. If anyone knows of other places in the database where "footprints" for assigning a user to group need to be left, I’d be grateful to hear about.

          Also, keep in mind that what little I know of SQL I’m getting from the online manual. There are undoubtedly more elegant, cleaner, etc. ways of accomplishing this. But this is what I’m coming up with ...
          MattC
            • 18913
            • 654 Posts
            Quote from: sottwell at Mar 18, 2010, 03:28 PM

            As far as I have been able to determine the only thing the web_users_attributes table really needs to have is the email. Without that the Manager doesn’t display the user in its list of web users.

            For what it’s worth : By doing the database upload method as described above, I can end up with users who do not have email addresses, but are shown in the Manager (Security -> Web Users) and are able to log in. Changes made to the profile as the user can still be saved without putting in an email address. Changes made to the profile as the admin won’t be saved unless there is an email address. An email put in by the admin can be deleted by the user via their profile once they log in.

            MattC
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              It must have been something else then; I seem to remember at one time that not having an email address in the web_users_attributes table would keep them from showing up on the list. Good, then, if I am wrong or this was fixed somewhere along the line.
                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