tags:

views:

179

answers:

2

Hi,

I have an excel list of 600 users with name, email, and role - that I need to add to the drupal site I'm building.

There are 2 roles distributed among the users.

As an added complication, the site is using the Content Profile module, so it would be a great help if for each new user account created, a corresponding profile node was also auto-created.

Any ideas how to batch-create the new users?

+2  A: 

How about the user_import module?

Dave DeLong
Looks perfect. Thanks!!
Michael D
A: 

I had the same thing, and created a module for this. Basically, it reads the user and what role to get from a file; in my case it was a CSV file with emailadres, name, role and stuff needed for the content profile.

Let's say you want user [email protected] and fill out automatically his content profile data Name, Sirname and City or something.

In your module:

read the line from the file create a new user create a new node, (stdClass object, give it the correct type ('profile_data' or whatever your content profile type is) and fill the rest of yout node and save.

A sample:

<?php

//create a form with a button to read the CSV file

function bulk_users_submit() {
    $users = 0;
    $handle = fopen(drupal_get_path('module', 'bulk_users') .'/'.DATAFILE, "r");
    if (!$handle) {
        return $users;
    }
    while (($data = fgetcsv($handle)) !== FALSE) {
        //this is similar to what the users.module does
        if (bulk_users_create_user($data)) {
            $users++;
            bulk_users_create_profile($data);
        }
    }
    fclose($handle);
    return $users;
}


function bulk_users_create_profile($user, $data) {
    $node = new stdClass();
    $node->title = t('First and Last Name');
    $node->body = "";
    $node->type = 'first_and_last_name';
    $node->created = time();
    $node->changed = $node->created;
    $node->status = 1;
    $node->promote = 0;
    $node->sticky = 0;
    $node->format = 0;
    $node->uid = $data['uid'];
    $node->language = 'en';
    $node->field_firstname[0]['value'] = $data['firstname'];
    $node->field_lastname[0]['value'] = $data['lastname'];
    node_save($node);
}


?>

not tested, but the idea is clear i hope.

Dr. Hfuhruhurr

related questions