MyBB Community Forums

Full Version: attachement problem with vbulletin4 to MyBB merge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I migrated the Vbulletin4 forum to MyBB. Everything went smooth during the process but after checking posts manually afterwards I noticed that something strange happened with the attachments.

If a post has more than one attachment, the merge system has picked only one attachment to the filesystem. I don´t know is it first, last or random. All attachments seem to be in place on the post, but all links point to the same physical file.

This has not happened to all posts with more than one attachment. I manually went through around 50 posts and around half of them had this problem.

I started migrating again to the test server and the problem seems to be there also.

There's a screenshot from the MyBB database (mybb_attachement table) which I believe points to the problem.

Any suggestions on what to do next? I can redo migration if I would know what to fix in Merge.

MyBB version 1834
Merge version 1823
PHP version 7.4.33
Vbulletin4 version unknown
I cannot answer what caused the problem, but I can tell you normal field entry format.
Example:
201309/post_34_1379879724_2a412fe948677cc4e5b35959b6430c7c.attach

folder/post_number_unixdate_filename.attach

In normal forum operations, first line creates the filename, next line prepends the upload path. Code is from inc/functions_upload.php
 515      // All seems to be good, lets move the attachment!
 516      $filename = "post_".$mybb->user['uid']."_".TIME_NOW."_".md5(random_str()).".attach";
 517  
 518      $file = upload_file($attachment, $uploadspath_abs."/".$month_dir, $filename);
Thanks! 

So it looks like filenames are generated only partial and problem seems to be in the part what gives randomized string to filename.

I´ll try to replace "md5(random_str())" -part with something else what generates unique strings and try to run Merge again.

I believe I found the problem.

At first I edited code in inc/functions_upload.php file. It did not change merge behavior. But it changed filename naming process due normal attachment uploads.

Then I seek another php files what could relate to Merge uploads. I found /merge/boards/vbulletin4/attachments.php

Found line about attachment naming which seems to miss totally code that generates unique ending to filename;  

Quote:$insert_data['attachname'] = "post_".$insert_data['uid']."_".$data['dateline'].".attach";


So I edited this line to:
Quote:$insert_data['attachname'] = "post_".$insert_data['uid']."_".$data['dateline']."_".md5(random_str()).".attach";


Started attachment merge again and looks like it is generating unique filenames now both in filesystem and database in case where there is more than one attachments in a post.  Have to wait and see how posts looks after merge.
Yes, victory!

"Re-Merge" is complete and all attachments are now in place like should be.

Thank you HLFadmin for pointing me to the right direction
Thank you Teroluu, your fix cured my problem in test migrating VB 4.2.5 to MyBB 1.8.36. For posts with multiple images, I'd either have one image that was the same for all images, or multiple copies of the same image. Funny thing was, the database showed different filenames, and manually downloading them and viewing them locally showed they were different, but on the forum it would be the same image. I eventually upped the PHP version from 5.6 to 7.4 and dropped the number of attachments it would process in each batch. This also solved a problem of PM's not migrating, By reducing the number processed allowed the corrupt one to be skipped and rest to go thru.

Now I gotta figure out how to clean up the database from the embedded image file pointers, our host only runs MySQL 5 so can't use a variable when using replace.