Problem/Motivation
Users of User Import may also want to import Profile 2 fields.
On the project page, it says:
Profile 2 fields not yet well tested, this feature is in development.
This is not correct. This feature is not being developed by any of the project's maintainers. While there is a patch provided by users of the module in this issue thread. The principal author of said patch says in comment #22 that:
I'm not using this patch anymore, now I prefer to import only the basic info with user import and then I import the Profile2 part of the profiles with the feeds module. I have to do an extra step, but feeds is much better and reliable.
Based upon that, the patch should not be committed, but alternatives listed in the next section should be recommended on the project page.
Proposed resolution
Those who need do do such imports should use Feeds or this project on GitHub.
Remaining tasks
None
Original report by DarrellDuane
Although I see on the main module page that Profile2 fields are not well tested, I didn't see a formal issue for this task, so I wanted to create a place for us to be able to talk about progress on this issue. Robert, or others, whats the latest?
Comments
Comment #1
scuba_flyI don't see any profile2 fields only standard ( email, username, password ) and taxonomy user fields as options available.
My guess is that after you import ( the sample.txt ) you should be able to match those fields to the profile2 fields in "field match" ?
looking in the code I noticed
content_profile_get_types()function being called.I think this was a drupal 6 function and should point to the profile2 version of this function in drupal 7
The drupal 7 version in profile 2 is profile2_get_types()
I see this is in the content_profile.inc file so not sure this is the place to be altert or that a new .inc file should be made?
Any suggestions are welcome of course. I'm willing to contribute to this module but I'm not considering myself a drupal developer expert.
Comment #2
scuba_flyI tried adding a profile2.inc in the 'supported' folder
In it I put the following code to start with:
But the hook_user_import_form_field_match() is not called...
Comment #3
mrdth commentedFlushing caches works to get this new file picked up by the module. I got the profile2 fields listed by using the following in profile2.inc:
(Basically combining what you had above with the hook_user_import_form_field_match function from the fields.inc file.)
Comment #4
druipol commentedI made an patch from previous comment.
Comment #5
MM10 commentedThanks for this... I had some trouble making the Profile2 fields available. I then I realized the patch was supposed to be applied within the support directory... and now it brings up the fields- thanks!
Comment #6
schifazl commentedI don't know if I'm doing something wrong, but it doesn't work for me. When importing I can see the profile2 fields and match them to the CSV file columns, I get no errors, but the profile2 fields aren't filled.
I constantly get this warning, I don't know if it's related to this problem: Warning: Creating default object from empty value in _user_import_settings_save() (line 574 of sites/all/modules/user_import/user_import.module)
Comment #7
armyofda12mnkeys commentedSolution #3 brings up the profile2 fields...
But I get the same warning when importing.... and the mapped profile2 fields don't actually get imported and saved to db.
We are using php5.2.17 and haven't gotten a chance to goto 5.3 yet. Do you think thats an issue causing import problems and warning above?
Comment #8
armyofda12mnkeys commentedNote: php5.3 makes that warning go away... but still doesn't populate the profile2 fields.
Let me know if any patches/updates I can try if you know what could solve the issue as I can test on my local box anytime.
Comment #9
armyofda12mnkeys commentedComparing now to the other includes, i assume it doesn't work because the profile2.inc file above doesn't include the other hooks that should be in there.
mrdth, do you have the full profile2.inc if you got it working? otherwise I can maybe take a look next weekend at figuring it out.
Comment #10
guntherdevisch commentedHey armyofda12mnkeys,
I also want to import profile2 fields, did you made any progress meanwhile? :)
Thanks,
Gunther
Comment #11
armyofda12mnkeys commentedSorry Gunther, didn't have time to look at it yet and decided to avoid Profile2 for now.
Comment #12
alibama commentedlikewise - see fields, don't get the data imported - new install, dev modules + patch
Comment #13
ximix commentedAlibama,
You have to write code for hook_user_import_after_save
Comment #14
ximix commentedI made a patch for complete process.
Comment #15
schifazl commentedIt works, great job! But it has two issues:
Comment #16
schifazl commentedOK, I've resolved the two problems found in patch #14, now in the "New import" page, under the Options fieldgroup, you can choose in which Profile type the values will be imported :)
EDIT:
Sorry, I have forgotten that you need to apply also this patch to the Profile2 module: https://www.drupal.org/node/2331435
If you don't want to apply that patch you can simply replace
$profile->defaultLabel();with
$profile->label;on the 4th line of the profile2_user_import_form_fieldset function
Comment #17
rooby commentedI would really like to see this as major since profile2 has so many users and it so closely relates to the importing of users, but technically feature requests are not major.
Comment #18
rooby commentedA quick code style review (see https://www.drupal.org/coding-standards). I haven't done technical review.
These should be "Implements hook_name()." for D7.
This is messy. It should either align all equals or not align any of them (my vote is for the latter but it doesn't matter either way).
We should always use the form:
Lots of trailing whitespace here.
Unnecessary blank line here and also at the start of most functions in this patch.
Missing spaces before ( and after ).
There should be a blank line after the first line short description and any other description.
Comments should be on the line above the code, not after the code inline. Comments also should be proper sentences, with a capital for the first letter and a full stop at the end.
Missing space before ( and after ).
Comment #19
schifazl commentedThanks! Modified as you suggested and added a mini modification: in profile2_user_import_form_fieldset() the collapsed status is set to false. This is because when you save the import settings, only the profile settings will be saved. IMHO this should be changed and handled by the module, not by supported/user_import.inc
This patch still depends on https://www.drupal.org/node/2331435
Or you can simply replace
$profile->defaultLabel();with
$profile->label;on the 4th line of the profile2_user_import_form_fieldset function.
I don't know that to do with this. Wait that the Profile2 guys accept that patch or continue here without the defaultLabel()?
Comment #20
rooby commentedComment #21
finedesign commentedI just tried using the dev version of user import to see if it would import to Profile 2 fields. I don't see them listed after importing a csv file. Is the above approach the only workable solution? I don't know how to run a patch and would appreciate help.
Comment #22
schifazl commentedHere you have some info on applying patches.
Anyway I'm not using this patch anymore, now I prefer to import only the basic info with user import and then I import the Profile2 part of the profiles with the feeds module. I have to do an extra step, but feeds is much better and reliable.
Comment #23
Coyote6GraphX commentedI know this is old, but for anyone needing to do this still, it doesn't need to be done as a patch. It can be a separate module, that way it doesn't need a patched on each module update.
https://github.com/Coyote6/drupal-7-user-import-profile2
I only briefly tested the code, and it worked for the two fields I was importing. Hope it helps others. Thanks.
Comment #24
gisleUpdating issue summary based upon comment #22 and comment #23. Setting statusb to "Fixed". Anyone that disagrees has two weeks to repoen.
Comment #25
gisleChanging status.