Bug tracker
attachment count zeroed (fix completed in vcs)
1) Create a post/topic and put 2 or more attachments
2) Once you post it, go in edit mode
3) Erase one of the attachment
4) Press CANCEL (This is important, as if you press "submit" there is no problem)
5) ... all the attachments have disappeared..
I checked the DB, searching for a fix and I noticed that post_attachment in the table phpbb_posts is 0.. I do not know what this is supposed to be.... but.. when I put it back to 1 the attachments appear again.
Comments / History
here is the value of post_attachment in function of the action..
action - post_attachment
create post with 2 attch - 1
edit, erase one - 0
submit - 1
action - post_attachment
create post with 2 attch - 1
edit, erase one - 0
cancel - 0
I did a little fix myself.. not a fix actually, just a hack.. I'd appreciate a better solution...!!
Here is the hack, in file posting.php (line 49). The fix is enclosed by /***.. and ..***/:
- Code: Select all
// Was cancel pressed? If so then redirect to the appropriate page
if ($cancel || ($current_time - $lastclick < 2 && $submit))
{
/*********************************************************************************************/
//here we redirect w/o caring about post_attachment so... we just make sure it is correct
$sql_query_fix_post_attachment_check = 'select attach_id from phpbb_attachments where post_msg_id = ' . $post_id;
$result_fix = $db->sql_query($sql_query_fix_post_attachment_check);
// does the post have attachment, if so lets just update post_attachment..
if ($db->sql_fetchrow($result_fix)) {
$sql_query_fix_post_attachment = 'UPDATE phpbb_posts set post_attachment = 1 where post_id =' . $post_id;
$db->sql_query($sql_query_fix_post_attachment);
}
/**********************************************************************************************/
$redirect = ($post_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $post_id) . '#p' . $post_id : (($topic_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) : (($forum_id) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}index.$phpEx")));
redirect($redirect);
}
Regards
But thanks anyway
I think it should be fairly simple to fix it properly, just avoid putting to zero post_attachment after the attachment is erased... I have yet to find the right place.. if anyone knows, please, let me know!
I hope to see a fix soon!
Best Regards
First thing first I found where the attachments are deleted
Thanks
- Code: Select all
/************************ FIX ************************/
$sql = 'SELECT post_msg_id
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . '
AND is_orphan = 0';
$result = $db->sql_query($sql);
$remaining_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$remaining_ids[] = $row['post_msg_id'];
}
$db->sql_freeresult($result);
$post_ids = array_diff($post_ids, $remaining_ids);
/*****************************************************/
before this (line 941)
- Code: Select all
if (sizeof($post_ids))
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_attachment = 0
WHERE ' . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
}
and this before the next if for the messages..(I bet they have the same problem..)
- Code: Select all
/************************ FIX ************************/
$sql = 'SELECT post_msg_id
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $db->sql_in_set('post_msg_id', $message_ids) . '
AND is_orphan = 0';
$result = $db->sql_query($sql);
$remaining_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$remaining_ids[] = $row['post_msg_id'];
}
$db->sql_freeresult($result);
$message_ids = array_diff($message_ids, $remaining_ids);
/*****************************************************/
What do you all think? (I get a nasty mysql error [0] with the above code..
Best Regards