MyBB Community Forums

Full Version: [F] Merge posts - attachment(s) problem [R] [C-Michael83]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If you merge two posts and the first of them contains an attachment is is not shown anymore after the merge. The problem is that the attachmentcount is set to 0 in the threads table.

It's working correctly if the second post contains an attachment.

Steps to reproduce:
1. Create a new thread and attach a file to your post.
2. Create a reply.
3. Merge the two posts.
Hmm, shouldn't the attachmentcount be incremented to 1 when you attach the attachment to your first post then?
It's 1 before the merge. The reason for the change can be found in the function merge_posts():
$query2 = $db->simple_select("attachments", "COUNT(aid) as count", "pid IN({$pidin}) AND pid != '{$masterpid}' AND visible='1'");
$attachment_count = $db->fetch_field($query2, "count");

$db->update_query("threads", array("attachmentcount" => $attachment_count), "tid = '{$mastertid}'");
$masterpid is the ID of the first post and because of that the query returns 0.
I'll have to look at the logs, but I'm pretty sure that was put in place to fix another bug for some reason
Does this work? In inc/class_moderation.php find:

$query2 = $db->simple_select("attachments", "COUNT(aid) as count", "pid IN({$pidin}) AND pid != '{$masterpid}' AND visible='1'");
$attachment_count = $db->fetch_field($query2, "count");

and replace with

$query2 = $db->simple_select("attachments", "COUNT(aid) as count", "pid IN({$pidin}) AND visible='1'");
$attachment_count = $db->fetch_field($query2, "count");

I don't see why we wouldn't count the first post in the amount of attachments
I tested several cases and I could not find any problem. The fix is working fine.
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

With regards,
MyBB Group