FuturShoc Posted January 31, 2013 Posted January 31, 2013 Hi, folks! We're working on our first big website project using ProcessWire. We're no longer in "fiddle and play with PW" mode. We're committed. My question: The site will have a directory of organization members, each needing a login/pw and a profile page. We're planning to use the existing Users/Roles model of ProcessWire, but we need to generate several thousand users from a pre-existing text file. Now, I won't have a problem writing a plain PHP script to parse the text file and interacting with the database. BUT i could use some help understanding how the user details and fields are laid out in PW's default install. I'm discovering, as many of you already know well, that even users are just pages. This, however, makes it a bit less than obvious how one might generate users programmatically on the fly. I would welcome any input or guidance you might have in helping me know *where* to insert *what* into the DB schema. I'd also welcome any anecdotal experiences you may have had doing something like this yourself. Caveats?
FuturShoc Posted January 31, 2013 Author Posted January 31, 2013 Wow. I just stumbled on this: http://processwire.com/api/variables/user/ It looks like I don't even *need* to know the structure behind user accounts. By using the PW API, I can generate user accounts all day long... Am I right? So. Awesome. Thanks, Ryan! And everyone else here, of course. lol 2
Wanze Posted January 31, 2013 Posted January 31, 2013 You are right. If you need more fields (first name, last name, image etc.), you can add them to the user template. $u = new User(); $u->firstname = "Gonzo"; $u->lastname = "Ipsum"; $u->name = "gonzo"; $u->pass = "BamBam!"; $u->addRole("guest"); $u->save(); 1
SiNNuT Posted January 31, 2013 Posted January 31, 2013 Next to the using the API for this task you could also use this module for the task. I haven't tried it with Users myself but seeing that they are also 'just' pages i think it should be easy to import a couple of thousand users from a csv file. The module also gives some options on updating via csv.
ryan Posted January 31, 2013 Posted January 31, 2013 You can also do this: $u = $users->add('gonzo'); if($u->id) { $u->firstname = 'Gonzo'; $u->lastname = 'Ipsum'; $u->pass = 'BamBam!'; $u->addRole('guest'); $u->save(); } else { echo "That username is already taken, please choose another"; } The benefit of using $users->add() is that it actually creates and saves the user before you populate it, meaning you can exit out earlier if there is some error. But the main reason is that some fields (like files or images) require the page you are manipulating to have an ID before you can add files. So this saves you from having to think about that. If that's not a consideration, then it doesn't really matter which approach you take. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now