Dear friends

We are maintaining a site for our alumni association. This site is based ASP - MS Access. We are planning to move it drupal but not sure of how we can import users. Right now we have 1400+ records

Any suggestions?

Varun

Comments

sin’s picture

User management in Drupal is done by user.module inside /modules directory. It stores users as a rows in database. To import users you must write a PHP script parsing MS Access user table export text and calling user module to add new users or inserting rows directly according to user module db schema.

Roberto Gerola’s picture

Hi Varun.

My suggestions :

1. Make a simple export of your user table in cvs format.
2. Take a look at the table users in Drupal.
3. Modify the cvs file to create for each row a proper SQL
instruction to write this data in Drupal table
(A spreeadsheet tool could be particularly convenient :
each field in a column)
4. Launch the created script

If you need help in preparing the script, give me a sign.

Bye.

---
http://www.speedtech.it

sin’s picture

They are md5 hashed.

Roberto Gerola’s picture

Never tried, but MD5 function of MySQL can be used for populating password field ?

---
http://www.speedtech.it

sin’s picture

:)

maverickvarun’s picture

Thank you

I am sorry but i am new to mysql too , so i am not sure if can play with the system .

There is a module called user import but i does not seem to be working

regards
Varun

sin’s picture

Here is a signature of a function from user.module you will use to add users:

/**
 * Save changes to a user account or add a new user.
 *
 * @param $account
 *   The $user object for the user to modify or add. If $user->uid is
 *   omitted, a new user will be added.
 *
 * @param $array
 *   An array of fields and values to save. For example array('name' => 'My name');
 *   Setting a field to NULL deletes it from the data column.
 *
 * @param $category
 *   (optional) The category for storing profile information in.
 */
function user_save($account, $array = array(), $category = 'account') {
 ...
}

So your PHP importing script would be something like:

  $uexport = array();
  // open export file
  $f = fopen('c:\msaccess_csv_export.txt');
  while (!feof($f)) {
    // read a csv line and explode it to array
    $uimport = explode(',', fgets($f));
    // fill account object
    $uexport['login'] = $uimport[0];
    $uexport['pass'] = $uimport[1];
    $uexport['created'] = $uimport[2];
    ...
    // see user module for other parameters
    
    // add new user, get user new object returned with $user->uid set to new user unique id
    $user = user_save(NULL, uexport);
  }
  // close export file
  fclose($f);

Assuming msaccess_csv_export.txt is a comma separated user parameters with a new line for every user. It can be exported by MS Access.

Script like this will import users and they will be automatically assigned new id's. So if you want to preserve content ownership you have to use this new ids or change them with UPDATE query.