I'm trying to import some users and their content_profile data from one Drupal site to another. The schema are identical. Here's what I have done so far.

drush en user_import, node_import -y

Create the .csv file for users
mysql> SELECT *
-> INTO OUTFILE '/tmp/myusers.csv'
-> FIELDS TERMINATED BY ','
-> ENCLOSED BY '"'
-> ESCAPED BY '\\'
-> LINES TERMINATED BY '\n'
-> FROM prodprod.users WHERE `users`.`uid` > 1;

admin/user/user_import/add
Browse... /tmp/myusers.csv
Click Next
Field Match:
Select username
Select Password
Select Email address*

Import

processed 314
imported 21
errors 293

Which means 21 new users. This is perfect except the date data has not be imported. That's okay. I'm the consumer of free software here.

Next step - import content_profile data

Create the .csv file for content_profile
mysql> SELECT *
-> INTO OUTFILE '/tmp/myprofiles.csv'
-> FIELDS TERMINATED BY ','
-> ENCLOSED BY '"'
-> ESCAPED BY '\\'
-> LINES TERMINATED BY '\n'
-> FROM prodprod.content_type_profile;

admin/user/user_import/add
Browse... /tmp/myprofiles.csv
Click Next
Field Match
The Content profiles fields are available in the Select Lists as they were in the previous import. Howver, there is no email address so how do I proceed?

It seems like the answer is in front of me. The other option I'm working on is writing database queries in mysql. If I can make this module work, it will be optimal.

Thank you for your help.

Comments

robert castelo’s picture

If you want to import content profile date data try User Import 6.x-3.0-beta2 which has some support for that.

Needs configuration of date format on User Import configuration page.

esod’s picture

Thanks for your message. I loaded User Import 6.x-3.0-beta2 but I only see the Performance fieldset at admin/user/user_import/configure. Should I be looking some other place?

My main issue is not being able to load myprofiles.csv. Do I need to combine the 2 tables into one csv? That doesn't sound right or doable except with very specialized knowledge.

Thank you

robert castelo’s picture

There's also Profile Settings, but actual that's only for Profile module fields.

All the data should be in one csv file yes.

esod’s picture

Can you detail how to create such a csv?

In the meantime, here are the mysql queries I've hammered out.

/* 2 databases. dev and prod. In this case
moving users and their content profiles
from prod to dev */

mysql > use dev;

/* Inserts new users. I create non-clashing uids, nids, and vids
by adding 10000 and relying on AUTO_INCREMENT and IGNORE.
*/
mysql > INSERT IGNORE INTO users (SELECT uid+10000, name, pass, mail, mode, sort, threshold, theme, signature, signature_format, created, access, login, status, timezone, language, picture, init, data, timezone_name FROM prod.users);

/* Temporararily add UNIQUE indexes to content_type_profile
so IGNORE will work correctly.
*/
mysql > ALTER TABLE `dev`.`content_type_profile` ADD UNIQUE (
`field_profile_FIELD1_value` ( 20 ) ,
`field_profile_FIELD2_value` ( 20 ) ,
`field_profile_FIELD3_value` ( 10 )
);

/* Inserts new user profiles */
mysql > INSERT IGNORE INTO content_type_profile (SELECT vid+10000, nid+10000, field_FIELD1_value, field_FIELD2_value, field_FIELD3_value, field_FIELD4_value, field_FIELD5_value, field_FIELD6_value, field_FIELD7_value FROM prod.content_type_profile);

/* Removes the just added indexes */
mysql > ALTER TABLE content_type_profile DROP INDEX field_profile_FIELD1_value;

/* Adds new user profile nodes */
mysql > INSERT IGNORE INTO node (SELECT nid+10000, vid+10000, type, language, title, uid+10000, status, created, changed, comment, promote, moderate, sticky, tnid, translate FROM prod.node WHERE prod.node.type='profile');

/* Adds nodes_revision records */
mysql > INSERT IGNORE INTO node_revisions (SELECT nid+10000, vid+10000, uid+10000, title, body, teaser, log, timestamp, format FROM prod.node_revisions WHERE prod.node_revisions.nid IN (SELECT nid FROM prod.node WHERE prod.node.type='profile'));

I still need an UPDATE query for node for existing users who have created content profiles because those new records are inserted into dev with the newly generated uids. For example, Say users.uid 20 creates his user profile, that node record is assigned a uid of +10000. This query:

UPDATE node content_type_profile SET uid = 20 WHERE content_type_profile.vid =11160;

works just fine, but must be made to work programmatically.

This query is not working.

UPDATE users p, node pp
INNER JOIN node, content_type_profile SET pp.uid = p.uid
WHERE node.vid = content_type_profile.vid;

Any suggestions or feedback? Thanks

robert castelo’s picture

Status: Active » Closed (works as designed)

Have you tried Node Export module to create the csv file?

Beyond that there's not much I can help with here.