Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm migrating roughly a thousand users from another site into a brand new drupal site. I'm going through a database and calling user_save(...); with the appropriate info.
This works great.
However, in the content profile I have things like their address, phone number, bio, all sorts of that information attached to a node. I know how to create a normal node programmatically, but how do I create a content profile node programmatically that is attached to a user?
Comments
Comment #1
mcaden CreditAttribution: mcaden commented-= Mission Accomplished =-
I created a user, then set the uid of the node equal to the new author. That was all. For the benefit of anybody else needing this I've pasted it below (with table/column names edited to generic names).
Note: Transferring old user passwords like I am in this snippet will only work if the previous developer was FAIL and left the database passwords plain-text.
Comment #2
mcaden CreditAttribution: mcaden commentedOops, forgot to change tags.
Comment #4
NeoID CreditAttribution: NeoID commentedThanks for the code, but it's just generating entries in the database without ever finishing.
Has there been any changes to the module that might affect this?
Comment #5
fuzzy76 CreditAttribution: fuzzy76 commentedIt's better to omit the format when saving nodes. That way, node_save() will use the default format for the content type. I used your code, but ran into weird permission problems. After a lot of debugging, I noticed our site does not have an input filter with ID 1 at all.
Comment #6
brandonratz CreditAttribution: brandonratz commentedMy use case:
List of contacts with extensive 'content profile' information (no user).
When a new user registers.
If their profile exists; tie the user to the existing content profile...
Any ideas?
Comment #7
froto CreditAttribution: froto commentedThis is brilliant!
Almost exactly what I need...except...I am working with /node/add/profile as admin user and I want to create an entry in users table for a newly created content profile instead of the Content Profile module trying to link it up the admin user. Basically, I want to give admin user ability to create a new user + their content profile... this is proving to be a nightmare ...
How can I accomplish this outside of modifying Content Profile modules hook_node_api ...??
Desperate for help....
THANKS!