MyBB Community Forums

Full Version: Custom Converter Module Issue (SOLVED)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm writing a custom converter module, and when I tested the users import before it imported duplicates by appending the table prefix and their previous user id to the end of their user names. I assumed this was the correct functionality, and want it. However, I accidentally deleted the user import portion of the module (don't ask, I hadn't slept in like 40 hours), and now I've taken another copy from the phpBB3 directory (the dir I copied everything from to mod them for the other board system) and performed all the same changes to it. However I'm now getting and SQL error from duplicate user names.

Quote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1062 - Duplicate entry 'Test User' for key 2
Query:
INSERT INTO mybb_users (usergroup,additionalgroups,displaygroup,import_usergroup,import_additionalgroups,import_displaygroup,import_uid,username,password,salt,loginkey,email,regdate,lastactive,lastvisit,website,showsigs,signature,showavatars,timezone,avatardimensions,avatartype,avatar,lastpost,icq,aim,yahoo,msn,hideemail,allownotices,regip,lastip,longregip,longlastip,language,passwordconvert,passwordconverttype,postnum,invisible,birthday,birthdayprivacy,subscriptionmethod,receivepms,pmnotice,pmnotify,remember,showquickreply,ppp,tpp,daysprune,timeformat,dst,buddylist,ignorelist,style,away,awaydate,returndate,referrer,reputation,timeonline,showcodebuttons,totalpms,unreadpms,pmfolders,notepad,threadmode,showredirect,dateformat,dstcorrection,warningpoints,moderateposts,moderationtime,suspendposting,suspensiontime,coppauser,classicpostbit,loginattempts,failedlogin)
~~privacy snip~~

Now, can someone slap me and tell me what I messed up to change the functionality here? Maybe I'm still too tired despite 9 hours of sleep. I don't know. But I don't see anything in the code that would do this.
Is the problem that it is trying to insert the user even though the username already exists.

The problem could be the comparison function (it may be incorrectly comparing a UTF8 username on the DB Table to an ASCII username in PHP or something to that effect)? You can manually run the checking query in phpMyAdmin and see what it does.
Isn't that function standard for all the import modules though? Because importing from phpBB3 board works fine. Even with duplicate user names. I haven't changed any of that stuff, don't need to. The only thing I've had to change is a few Query lines and the names of fields. At least for the users import. Other modules were more complex. I'm downloading Zend Studio right now so I can debug it. Any other ideas shoot them forward. Thanks.
Well it's possible that there are some differences between database and table coalitions
Of course there are, but the users tables were easy. And this is the 2nd time I've written it. First time it worked perfectly, this time I'm getting this error. Was more looking for suggestions on where to look for typos/mistakes in the users import file than anything else. Since nothing else was changed in terms of user import.
I've narrowed it to the file
convert/resources/modules/users.php
For whatever reason it isn't detecting the duplicate username in here as it should. I've double checked it with a completely stock copy to make sure I didn't accidentally change it. Its stock. It just isn't entering the routine for whatever reason.

Here is the code:
// Check for duplicate users

		$query = $db->simple_select("users", "username,email,uid,postnum", "LOWER(username)='".$db->escape_string(my_strtolower(encode_to_utf8($user[$this->settings['username_column']], $this->settings['encode_table'], "users")))."'");

		$duplicate_user = $db->fetch_array($query);

		$db->free_result($query);
		
		echo "Place One";
		echo "  ".$duplicate_user['username']."  ";

It echoes Place One properly, but $duplicate_user['username'] echoes empty. Anyone have any idea why?

Heres the username encoding for the old username:
$insert_data['username'] = encode_to_utf8($data['user_name'], "users", "users");

As you can see it is being encoded properly. Its a direct copy of the line from the phpbb3 convert set, only thing changed is the $data['user_name'] to make it match the database I'm converting.
Oh geeze, I really was too tired yesterday. 5 minutes of looking at the code showed me what I did wrong. I forgot to properly change the settings array at the top of the user module from username to user_name to match my DB. Thanks anyways guys Wink You can kick me in the head now for writing code without sleep... something I know better than to do!

Oh yeah, and I do need to say thanks for writing MyBB and the MyBB Merger system. They're VERY nice.