Admin functions - allow for automation/bulk operations?
I have started working on some scripts that would allow me to perform some admin operations, such as adding users in bulk (i.e. adding 600 users from a CSV file)
Currently many of the admin functions require manual input... either they look for a POST variable, or a GET argument. I believe it would be a good idea if these functions had an automation argument, which would allow for scripting and performing tasks in bulk.
For example, the existing argument list would be extended by one, maybe named '$auto', defaulted to NULL. Normal operations would ignore the extra argument and work the same way they do now. But by providing a value for $auto, POST and GET arguments could be replaced. And instead of displaying an on-screen message signaling success or failure, the status would be returned to the calling function. These changes would simplify writing functions allowing for multiple user creations/edits, etc.
Currently I am making these changes in the functions I want to automate. But asking for committed changes to core modules/functions seems unlikely.
I'd like to know if other people are creating solutions for automation, and if there would be support for adding automation flags to the existing core admin functions. I would be happy to contribute to this project, but only if there is a chance for future incorporation into the core. Comments welcome.

go for it
lots of people have to import users, nodes, comments, etc.
we should be enhancing our 'save' functions to support this as needed. However, using an automation flag is rarely necessary. See node_save() for example. One can call that directly and it doesn't have any automation flag.
reason for the flag
The first operation I implemented was adding users in bulk (from a CSV file). admin_create_user works fine as-is... I can easily create a new user. But as soon as I want to add additional info (full name, role, etc.) I need to use admin_edit_user.
This looks for a GET argument in the URL to determine the user id, and it looks for a POST variable to determine the current operation. Both of these, I can't send automatically, they need to be overridden somehow. Secondly, admin_user_create doesn't return a value, so I don't know the newly created "uid" (user id), to pass along to admin_user_edit, even if I could use it.
Now, I considered going straight to the "save" functions, however I don't think it is smart to pass up the validation of the calling functions (admin_user_create, admin_user_edit). I mean, I could also go straight to the DB by writing a SQL statement, but I don't think that is smart either.
In my case, I modified both of these two functions, so automation works. I added an argument (the "flag") to each function that, when set to TRUE, signals that this is an automated operation, so it needs to behave a little differently (admin_user_create now returns the new uid, and admin_user_edit looks for the POST and GET data in the "edit" array)
I don't expect these changes to be committed... they are just quick hacks. What I would like to see is a discussion about the best way to implemement automated operations, and to determine a standard procedure or API that would work with all existing admin functions. This isn't going to be easy since the admin functions come from lots of different modules. But I think we should start to look at this seriously.
Need sample code for bulk user w/ profile creation.
I would like to bulk load 150 users into my site including addresses and other profile options if possible. Can someone send me sample php for this? Or just point me in the right Forum post or code website. My contact is loron on yahoo.com
Have a look: http://cvs.dr
Have a look:
http://cvs.drupal.org/viewcvs/contributions/modules/devel/generate/gener...
It won't handle profiles, but you can extend it to do so.
Updates for 4.5.2
http://cvs.drupal.org/viewcvs/contributions/modules/devel/generate/gener...
Thanks for this tool, works beautifully with a couple of small updates for 4.5.2
Problem with _user_authenticated_id() not working and new passwords being assigned by user_save() rather than using the encrypted password supplied in the CSV.
Modified lines from brute force solution below. It Worked For Me (TM):
$array = array("name" => trim($data[0]), "pass" => $data[1], 'init' => $edit['mail'], "mail" => $data[2], "status" => 1, "roles" => array(_user_authenticated_id() => 2));user_save($account, $array);
db_query("update {users} set pass='%s' where mail='%s'", $data[1], $data[2]);
Theatre Australia
http://theatre.asn.au/
"Quick" Questions
gmalcolm: you have "Allow messages to be sent to you" turned off so I will post here and hope for the best.
Did you or anyone ever come up with some code to import a list of users and profile info?
ok... I need some assistnace...
In th ecurrent version... this is what is listed for a user:
uid, name, pass, mail, mode, sort, threshold, theme, signature, created, changed, status, timezone, language, picture, init, dataIn the PHP code you are only updating:
name, pass, init, mail, status, rolesIs there a difference in versions here? you include "roles" where Role now has it's own table called: users_roles which basically has UID and RID
Moving forward...The way I see it is I need to do the following via:
- insert user data to users table Adding uid+1 to each user.
- get above uid and insert lines for each role they need.
- profile data is stored in a table called profiles_values: which is a list of UID, value for the profile, and FID which is the field id for the profile found in table profile_fields.
ok... lets break this down.
Lets say I have a CSV with the following:
Email, UserName, Pass, NameLast, NameFirst, Company1st: I would find a default known hash for 'PASS' like: 40be4e59b9a2a2b5dffb918c0e86b3d7 which equals welcome. I would use that for all users's pass to keep things simple.
2nd: I would use the above PHP to loop over the CSV and stamp the database with a starting ID if say 10 (Adding ++1 to each user since auto incriment is not enabled in the database), I would then add the email, and know HASH for Pass.
3rd: I would run a second insert using the ID 10 (++1) to add the rid of 2 for authenticated user.
4th: I would then pull the profile fields and enter a single line for each with the uid, the know fid, and the provided value.
5th: I would lastly update the table sequences with Update sequennces SET id = 2000 WHERE name='users_uid' adding in the current count of users.
Your code addition above:
db_query("update {users} set pass='%s' where mail='%s'", $data[1], $data[2]);Why is this being performed if the line above it already stamped the database with the password?
Any thoughts on all of this before I get started? I will follow up when I have a "huge win story to share" or a "sob story of complete loss". Either way post you story here to encourage me.
Thansk
ok.. I get it!
I see... the following function explained alot for me: http://drupaldocs.org/api/head/function/user_save
Basically I create an array with all the info I need for user and role... then the function does all the work.
But in the end.. I could just loop over a list and do an insert. Than use that ID to add a new line for each Profile item. I'll play and see.
try the userplus module for GUI "bulk" operations
http://drupal.org/node/50864