MyBB Community Forums

Full Version: Attachment dont attach in topic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I merge from mybb to mybb and merging it's complete. After rebuid it attachments dont include in no one topic.
All attachment are orphan
Yes, it is known.
[Issue #1746]

I'll try and have this resolved over the next few days... probably on Wednesday since I know I'm busy tomorrow and Tuesday.
Thank you! Ihope you dont busy in next days! If are few day I can wait
Doesn't look like I'll have the time today for this because my gf didn't end up working today (no work at her job) so we're going to get some home repairs taken care of, and the taxes. Ugh. Taxes Sad

I'll do it tomorrow while she's at work through, probably before noon eastern time.
Ok, apply the following change to merge/boards/mybb/attachments.php and then start merge over from beginning (after reverting to a pre-merge backup of the MyBB board you're merging to)

Change:
		// Restore connection
		$query = $db->simple_select("posts", "message", "pid = '{$insert_data['pid']}'");
		$message = $db->fetch_field($query, 'message');
		$db->free_result($query);
		preg_match_all("#\[attachment=([0-9]+?)\]#i", $message, $matches, PREG_SET_ORDER);
		if(count($matches) > 0)
		{
			foreach($matches as $aid)
			{
				$message = str_replace('[attachment='.$matches[1].']', '[attachment='.$aid.']', $message);
			}
		}				
		$db->update_query("posts", array('posthash' => $insert_data['posthash'], 'message' => $db->escape_string($message)), "pid = '{$insert_data['pid']}'");

To:
		// Restore connection
		$query = $db->simple_select("posts", "message", "pid = '{$insert_data['pid']}'");
		$message = $db->fetch_field($query, 'message');
		$db->free_result($query);
		$message = str_replace('[attachment='.$data['aid'].']', '[attachment='.$aid.']', $message);
		$db->update_query("posts", array('posthash' => $insert_data['posthash'], 'message' => $db->escape_string($message)), "pid = '{$insert_data['pid']}'");

I have no idea why the logic there was so screwed up and convoluted... but it was. It isn't now Smile & the new code should work. Let me know if it doesn't.
OOPS! Also change:
$insert_data['pid'] = $this->get_import->pid($data['attach_pid']);

To:
$insert_data['pid'] = $this->get_import->pid($data['pid']);

So that the pids are set correctly.
thank you work it very well