MyBB Community Forums

Full Version: MERGE and IMPORT of users
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there,

I am in the process of merging an online community of roughly 20,000 people (of which 6,000 or so registered) into the mybb usertable. Now the forum that we use has about 800 registered users.

Here's the dilemma I could use some help with:

- some of the 800 registered forum-users (most) are also in the population of 20,000 people...most probably in the 6,000

Here's what's already done (or being done at this very moment)...

- added details to the userprofile (ie. address-detail, contact-detail, job-details etc)
- changes made to the system where certain groups of details are hidden from everyone or only available to a given group
- changes to the system where the user him/herself is in charge of what details are shown to others...

What I am GOING TO be doing:

- import ALL 20,000 people into the mybb-usertable into a new GROUP called eg. UNREGISTERED ALUMNI
- try to match the 6,000 registered users from the original database with the 800 registered in MyBB and MERGE the records (QUESTION1 BELOW)
- mass-register the rest 5,200 records in MyBB with their existing username/password combo from the original database into the MyBB-usertable and move them to a group called REGISTERED ALUMNI
(QUESTION2 BELOW)
- have a moderated registration that will notify any new registrations, that claims to be an alumnus, to a person who will check the new registration against the remaining 14,000 records and if match is found, merge the records and move the person to the REGISTERED ALUMNI -group, otherwise accept registration and move the person to REGISTERED GROUP

So....rather complex thingy....but I believe we can pull it off.....here are the questions:

QUESTION 1
------------
What happens with the merge? Can I make the merge-function to basically import the data from the other record to the other....or do I just have to select which one is the master-record and the data from the other record will be deleted? Just trying to find out if I need to do a lot of manual merges on sql-level or can I have someone else in the organization do the merges via the merge-tool in admincp?

QUESTION 2
------------
I want to mass-register over 6,000 people. I will get their current username/password in straight-text format from the current-database, but I want do the entire MD5+SALT thing on the passwords prior to importing the data. How can I do it?

cheers,
Kimmo
Ok. I think what I'm about to tell you is accurate, but I'd wait for 'official' reply Smile
(Some info: I've never used the MERGE function of mysql. So for me, a PHP solution would be best, rather than trying to alter sql files to make them merge properly)

QUESTION 1
You will have to be careful with column names and types. Some columns could have been deleted in pr2 and some added that are needed (like the new salt/loginkey). So you should be careful if trying to do a straight merge.

QUESTION 2
The old (mybb rc4) password was generated using the md5 function in PHP. Luckily it's basically the same thing in Mybb PR2 with the salt added. You will have to get the user's passwords, then using a PHP solution, loop through the 5000 users. For each user you'll have to do the following,
1) get their old mybb rc4 password (should be simple if you know some php)
2) update the password and get salts using the code below
$salt = generate_salt();
$saltedpw = salt_password($old_mybb_rc4_password, $salt);
$loginkey = generate_loginkey();
(the functions used can be found in "inc/functions_user.php").
3) insert into the new database. The salt is stored in the field 'salt', the md5'ed password is stored in 'password', and loginkey is stored in 'loginkey'
decswxaqz Wrote:QUESTION 1
You will have to be careful with column names and types. Some columns could have been deleted in pr2 and some added that are needed (like the new salt/loginkey). So you should be careful if trying to do a straight merge.
I think you misunderstood me a little....the database I am importing from has nothing to do with MyBB....it's actually an Oracle-database somewhere else...so the entire dataset will actually be imported into PR2 usertables (revised) and only then merged

decswxaqz Wrote:QUESTION 2
The old (mybb rc4) password was generated using the md5 function in PHP. Luckily it's basically the same thing in Mybb PR2 with the salt added. You will have to get the user's passwords, then using a PHP solution, loop through the 5000 users. For each user you'll have to do the following,
1) get their old mybb rc4 password (should be simple if you know some php)
2) update the password and get salts using the code below
$salt = generate_salt();
$saltedpw = salt_password($old_mybb_rc4_password, $salt);
$loginkey = generate_loginkey();
(the functions used can be found in "inc/functions_user.php").
See the answer above, but in principle, this is what I am looking for....looping of the thingy to create the MD5+SALT values for password and salt... and I am limited to the tools I have at home....of course I could take it to another database...hmm...I'll think about it..

decswxaqz Wrote:3) insert into the new database. The salt is stored in the field 'salt', the md5'ed password is stored in 'password', and loginkey is stored in 'loginkey'

Yes..this I know already....it's the first 2 questions that are more of the dilemma...
Oh. Sorry I thought it was from previous version of MyBB. It depends on how you've stored the passwords in Oracle then? I hate Oracle. It makes me cry.
like I said I will get the username and password info as straight-text file so that won't be an issue....the mass-encryption with MD5+SALT is.....well for me for the time being anyway....sure I'll get around it somehow...
and the merge...I am trying to make the switch from one distributed system (sitting on Oracle now) + MyBB....merge together...and everything will be under one integrated system....based on MyBB...
there'll also be a CMS that will allow me to develop my own 'modules' to place on any page while it gets the data from the mybb-dbase..
my question in regards to the logic of the merge-function in teh admincp still remains unanswered? What does this function cover? key-references in posts/threads/polls anything else?
The merging users in the Admin CP allows you to basically merge 2 users of the board into one. This is used when you know one person has registered twice. Almost everything should be copied to under the resulting user's account (posts, threads, PMs, events, etc)
this part I do understand yes....but what happens if there's conflicting information in regards to for example birthdate or something like that....is there a possibility to select which one remains....or is there a possibility to create a mod that would enhance the merge-function to this?
I don't know about that, but if it's Oracle then you'll have to do a sort of PHP script.

You'd have to extract them with a unique caracter which is not mentioned in any fields, example: "," or ";" or an ascii character, example: "Թ" which is some ALT+1337 character. (That you should know/remember at the time of extraction.)

After then, you'll have to create a PHP script that gets the data, so let's say the data is "uidԹunameԹuemailԹuposts", each user in it's line and it's in a TXT file, you start your PHP code

<?php
  // Load the data.txt containing our data.
  $tmpbuff = file_get_contents("data.txt");

  // Split our $tmpbuff variable by each line to get each "user".
  $user = explode("\n", $tmpbuff);

  // Go in a "foreach" loop to check if each username = exists, else quit.
  foreach ($user as $x) {
    // Split it by our special character, ascii 1337.
    $x = explode(chr('1337'), $x);
    // Send a MYSQL query to check if user exists. (after you do the connection shizzle // I'm not sure about table/field names, so you change/modify it to your needs.)
    $cqry = mysql_query("SELECT uname FROM mybb_users WHERE uname=" . $x[1];
    // Check if the query to check existance failed or not.
    if(mysql_num_rows($cqry)) { $exist = 1; }
    // User is non existant, procced to add.
    if($exist == 0) {
      mysql_query("INSERT INTO mybb_users (uid, uname, email, posts) VALUES ($x[0], $x[1], $x[2], $x[3])");
      print "added user: $x[1]";
    // User exists, fail.
    } else {
      print "ignored user: $x[1] (already exists!)";
    }
    // Set $exist to 0 again not to fail again.
    $exist = 0;
  }

That's about how the code should be..