MyBB Community Forums

Full Version: Is there a way to merge custom profile fields?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm converting several phpBB 3.0 boards to myBB. All of them have made extensive use of custom fields.

If I re-create all the custom fields on myBB prior to merge, is there a readymade solution to map the source custom fields with the myBB custom fields so they can also be transferred on merge?

If not, what's the best way to approach this as far as modifying the merge files to support it? Having to manually designate which table/fields from phpBB should may to which table/fields in myBB on a per-user basis fine with me as long as it works. I hope that's okay to ask?

Heck, even a mySQL query I can run that matches user IDs between two tables in two different DBs on the same host and copies over a field would be really helpful. I'll be looking into this myself as probably the most straightforward solution, but my SQL skills are rudimentary at best.

Thanks in advance for any direction.
(2020-06-25, 05:25 PM)kirikiri Wrote: [ -> ]If I re-create all the custom fields on myBB prior to merge, is there a readymade solution to map the source custom fields with the myBB custom fields so they can also be transferred on merge?

Yeah seems there's no ready way to do so unless you code it yourself.

(2020-06-25, 05:25 PM)kirikiri Wrote: [ -> ]If not, what's the best way to approach this as far as modifying the merge files to support it? Having to manually designate which table/fields from phpBB should may to which table/fields in myBB on a per-user basis fine with me as long as it works. I hope that's okay to ask?

MyBB stores user-defined fields in table mybb_profilefields and their data in table mybb_userfields. Besides there are several fields like contact info. (website, icq, skype, google, etc.) are stored in the main user table mybb_users.
It seems something like this works fine. It will be a pain to manually handle this for about 20 custom fields per forum, but it works.

update DestinationDB.mybb_users, SourceDB.phpbb_profile_fields_data set DestinationDB.testbb_users.usertitle = SourceDB.phpbb_profile_fields_data.oldtitle where DestinationDB.mybb_users.uid=SourceDB.phpbb_profile_fields_data.user_id;

However, I just realised that user IDs aren't kept intact in the merge, which is a huge issue since I need them to match in order to copy fields over this way.

Is there any way to force UIDs to remain consistent in the merge? If I delete the user #1 in the source forum and only have the admin user (#1) on the destination forum prior to merge, then there shouldn't be any conflicts anyway?

While I understand that the Merge System is intended to have functionality to merge multiple forums into one, I think it'd be really beneficial to have a user select option for a 1:1 conversion that preserves UIDs, TIDs, and PIDs... we have a lot of shortlinks and such that rely on IDs to generate links, so having everything re-assigned is obviously not ideal.

I'm having trouble figuring out where IDs are re-generated though. The insert() function in resources/users.php seems to just prepare the importing data for insertion into the myBB db and prepare_insert_array() doesn't seem to do anything specifically with IDs, but insert() returns the new ID, so I guess the $data being passed to insert() already contains the new ID? But the import() function in phpbb3/users also doesn't seem to regen ID since it calls insert() directly after querying the old DB for values.

It seems like the old IDs are being temporarily stored to an import_uid column, which is dropped later... since users are imported before posts, would it royally mess things up if after importing users and before dropping the import_uid column, I just copied the import_uid values into uid? And then did the same later with TIDs and PIDs?

I'm not really sure how the merge process keeps user-post-thread associations intact while also changing the IDs for all of these things...I'm not great at this stuff, so some direction would be really appreciated.
Okay, I got it sorted. Since while searching for a solution for this issue, I found several other threads on the issue, I'll post this for anyone else who wants to do a 1:1 forum migration and retain all user IDs, thread IDs, and post IDs. I didn't bother with forums, PMs, or other items with IDs since those aren't really things that are linked as frequently.

I made these modifications for phpbb3, but I'm sure it works with others. You'll just need to replace the column names with what they are for your forum software's DB.

Basically,

Find in merge/boards/phpbb3/users.php:
$insert_data['import_uid'] = $data['user_id'];

Insert below:
$insert_data['uid'] = $data['user_id'];

Find in merge/boards/phpbb3/posts.php:
$insert_data['import_pid'] = $data['post_id'];

Insert below:
$insert_data['pid'] = $data['post_id'];

Find in merge/boards/phpbb3/threads.php:
$insert_data['import_tid'] = $data['topic_id'];

Insert below:
$insert_data['tid'] = $data['topic_id'];

Find in resources/modules/users.php:
$uid = $db->insert_id();

Replace with:
//$uid = $db->insert_id();
$uid = $data['uid'];

Find in resources/modules/posts.php:
$pid = $db->insert_id();

Replace with:
//$uid = $db->insert_id();
$pid = $data['pid'];

Find in resources/modules/threads.php:
$tid = $db->insert_id();

Replace with:
//$tid = $db->insert_id();
$tid = $data['tid'];

By default, the merger saves the old ID to a temporary column in order to use it to cross-reference posts to users to threads but the new myBB table this data is saved to has its own ID column which auto-increments, hence the mismatch.

This assigns the old ID to the new ID column while still keeping the temporary column for use elsewhere in the merge process.

Prior to merging, you need to ensure that there are no users/topics/posts from your source forum that conflict with your destination forum, since that will obviously cause errors. For example, in my first test, while the admin user on my source and destination had different IDs, they still had the same username, which caused errors. Make sure everything is different.

And once everything's imported, you can manually re-add custom fields and then run manual SQL queries for each one to cross-reference UIDs and populate them with the old data.