Map imported fields to roles
monkeybeach - August 28, 2007 - 13:20
| Project: | User Import |
| Version: | 5.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Ok I know you can assign roles for all the users you import, but is there a way to map imported CSV fields to roles so each user has the correct role(s) when importing, and not all the same ones?
I realise you could batch user import so each upload had a particular role assigned but I have a site where there are up to 20 roles and some users have 5, some have 7 etc.

#1
The attached file allows for a column to be specified which has a comma separated list of roles. It also provides an option to add roles that are specified if they don't already exist. It will preserve any existing roles, including those that might be specified to add to all imported users.
Unfortunately, because user_import relies on module_invoke_all to call additional functions, I had to name the functions in line with a module, and there is no module for roles. I chose to use system, which is admittedly kind of an ugly solution. It might be better to change this so that it is included in user.inc or user_import.inc, but until there's commitment to include this in the overall project, I wanted to keep the code separate. I'd be happy to adapt the code if there is interest in adding this to the project.
#2
I am attempting to implement the fix as provided by surge_martin, above for use in an E-learning site, but having trouble getting this to work in Drupal 6. The field is visible in the column mapping screen, but the following error appears after the import and no roles have been mapped or created:
warning: array_push() [function.array-push]: First argument should be an array in /homepages/14/d294720235/htdocs/modules/user/user.module on line 249.
I'm a noob when it comes to php, so I'm hoping a fix for this might be quite obvious to somebody out there.
#3
Interesting. I'm using Drupal 6.13 and user_import 6.x-1.2 and it doesn't seem to be parsing system.inc. Yours seems to be working, mrvinceo, where did you drop the file?
#4
Answered my own question, I think: modules/user_import/supported/ gets the file to parse.
When I run an import, however, I am not getting any errors: the users go into the DB, but don't get any roles set.
#5
Ok, I've got this working -- the signature for function system_user_import_data() had changed at some point since surge_martin had written the modifications, and just needed to be updated. The attached file works if you drop it into modules/user_import/supported/ on Drupal 6.13 and user_import 6.x-1.2
#6
Fantastic! nemcheck; you are a star, works perfectly now and is exactly what we needed to get the whole project off the ground. As for me, back to studying basic php!
Cheers again.
#7
Patch re-written and committed to User Import 6.x-1.3.
Will backport to User Import 5.x in near future.
#8
Thanks, mrvinceo! :) And thanks to Robert Castelo for the quick turn-around on the release!
#9
Fixed in user_import 5.x-2.9 for the Drupal 5 version.
#10
Automatically closed -- issue fixed for 2 weeks with no activity.