Bug tracker

This ticket has been moved to our new tracker. Open Ticket PHPBB3-8496 now.

attachment count zeroed (fix completed in vcs)

viewtopic.php?f=46&t=1700065

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

Edited ticket

Action performed by WorldWar on Jul 19th 2009, 19:11

Edited ticket

Action performed by WorldWar on Jul 19th 2009, 19:14

Posted by WorldWar on Jul 20th 2009, 01:13

Hello,

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

Edited post #170245

Action performed by WorldWar on Jul 20th 2009, 01:14

Edited post #170245

Action performed by WorldWar on Jul 20th 2009, 01:15

Posted by leviatan21 on Jul 20th 2009, 03:55

The problem with your fix is that only will work on Subsilver2 ( prosilver have no Cancel button ) and also will not work if the user didn't press the cancel button and directly click on any other link.

But thanks anyway ;)

Posted by WorldWar on Jul 20th 2009, 05:13

Thanks for the constructive comments! I had not think about those the other scenarios...! :)
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

Posted by WorldWar on Jul 20th 2009, 06:09

Hello there, I think I found the place where the crime is committed..
First thing first I found where the attachments are deleted :) in includes/functions_admin.php:941 .. here we set the post_attachment to 0 if sizeof(post_ids) is zero ... now.. I am no expert of php but.. why?! post_ids from what I understand is an array holding the ids of the post containing the attachment(s) which was(were) deleted.. but this doesn't imply that these posts don't have any other attachment.. maybe I am missing something... :) A very intriguing function..!

Thanks

Posted by WorldWar on Jul 20th 2009, 07:25

I personally think that that function should be modified as follows: adding this
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..:P can't find the error.. I am not a php programmer..!)

Best Regards

Edited post #170285

Action performed by WorldWar on Jul 20th 2009, 07:26

Assigned ticket to user "nickvergessen"

Action performed by nickvergessen (Development Team Member) on Jul 20th 2009, 09:18

Changed ticket status from "New" to "Reviewed"

Action performed by nickvergessen (Development Team Member) on Jul 20th 2009, 09:18

Changed ticket status from "Reviewed" to "Fix in progress"

Action performed by nickvergessen (Development Team Member) on Jul 20th 2009, 09:49

Linked ticket with changeset: r9843

Action performed by nickvergessen (Development Team Member) on Jul 24th 2009, 09:01

Changed ticket status from "Fix in progress" to "Fix completed in SVN"

Action performed by nickvergessen (Development Team Member) on Jul 24th 2009, 09:01

Linked ticket with changesets: r9893

Action performed by nickvergessen (Development Team Member) on Jul 30th 2009, 13:48

Linked ticket with changeset: r10142

Action performed by nickvergessen (Development Team Member) on Sep 13th 2009, 15:04

Linked ticket with changeset: r10186

Action performed by nickvergessen (Development Team Member) on Sep 25th 2009, 08:41

Ticket details

Related SVN changesets