Author: nickvergessen
Date: Fri Jul 24 09:01:29 2009
New Revision: 9843
Log:
Fix bug #48265 - Correctly set attachment flag for topics, posts and pms after deleting attachments - Patch by WorldWar and nickvergessen
Authorised by: AcydBurn
Modified:
branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html
branches/phpBB-3_0_0/phpBB/includes/functions_admin.php
branches/phpBB-3_0_0/phpBB/includes/functions_posting.php
branches/phpBB-3_0_0/phpBB/includes/message_parser.php
branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php
branches/phpBB-3_0_0/phpBB/posting.php
Modified: branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html
==============================================================================
*** branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html (original)
--- branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html Fri Jul 24 09:01:29 2009
***************
*** 174,179 ****
--- 174,180 ----
<li>[Fix] Banning an already banned user states to be successful, but has no effect (Bug #47825 - Patch by Pyramide)</li>
<li>[Fix] Do not add style-parameter to URL again, after admin re-authentification (Bug #18005 - Patch by leviatan21)</li>
<li>[Fix] Do not cut post-message in between HTML-Entities on search.php (Bug #31505 - Patch by leviatan21)</li>
+ <li>[Fix] Correctly set attachment flag for topics, posts and pms after deleting attachments (Bug #48265 - Patch by WorldWar and nickvergessen)</li>
<li>[Change] Change the data format of the default file ACM to be more secure from tampering and have better performance.</li>
<li>[Change] Add index on log_time to the log table to prevent slowdown on boards with many log entries. (Bug #44665 - Patch by bantu)</li>
<li>[Change] Template engine now permits to a limited extent variable includes.</li>
Modified: branches/phpBB-3_0_0/phpBB/includes/functions_admin.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/functions_admin.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/functions_admin.php Fri Jul 24 09:01:29 2009
***************
*** 892,910 ****
// Update post indicators for posts now no longer having attachments
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);
}
// Update message table if messages are affected
if (sizeof($message_ids))
{
! $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
! SET message_attachment = 0
! WHERE ' . $db->sql_in_set('msg_id', $message_ids);
! $db->sql_query($sql);
}
// Now update the topics. This is a bit trickier, because there could be posts still having attachments within the topic
--- 892,952 ----
// Update post indicators for posts now no longer having attachments
if (sizeof($post_ids))
{
! // Just check which posts are still having an assigned attachment not orphaned by querying the attachments table
! $sql = 'SELECT post_msg_id
! FROM ' . ATTACHMENTS_TABLE . '
! WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . '
! AND in_message = 0
! 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);
!
! // Now only unset those ids remaining
! $post_ids = array_diff($post_ids, $remaining_ids);
!
! 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);
! }
}
// Update message table if messages are affected
if (sizeof($message_ids))
{
! // Just check which messages are still having an assigned attachment not orphaned by querying the attachments table
! $sql = 'SELECT post_msg_id
! FROM ' . ATTACHMENTS_TABLE . '
! WHERE ' . $db->sql_in_set('post_msg_id', $message_ids) . '
! AND in_message = 1
! 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);
!
! // Now only unset those ids remaining
! $message_ids = array_diff($message_ids, $remaining_ids);
!
! if (sizeof($message_ids))
! {
! $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
! SET message_attachment = 0
! WHERE ' . $db->sql_in_set('msg_id', $message_ids);
! $db->sql_query($sql);
! }
}
// Now update the topics. This is a bit trickier, because there could be posts still having attachments within the topic
Modified: branches/phpBB-3_0_0/phpBB/includes/functions_posting.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/functions_posting.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/functions_posting.php Fri Jul 24 09:01:29 2009
***************
*** 1549,1554 ****
--- 1549,1569 ----
break;
}
+ if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post'))
+ {
+ $sql = 'SELECT 1 AS has_attachments
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
+ $result = $db->sql_query($sql);
+ $has_attachments = (int) $db->sql_fetchfield('has_attachments');
+ $db->sql_freeresult($result);
+
+ if (!$has_attachments)
+ {
+ $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0';
+ }
+ }
+
// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
$db->sql_transaction('begin');
Modified: branches/phpBB-3_0_0/phpBB/includes/message_parser.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/message_parser.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/message_parser.php Fri Jul 24 09:01:29 2009
***************
*** 1334,1340 ****
/**
* Parse Attachments
*/
! function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
{
global $config, $auth, $user, $phpbb_root_path, $phpEx, $db;
--- 1334,1340 ----
/**
* Parse Attachments
*/
! function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false, $post_msg_id = 0, $topic_id = 0)
{
global $config, $auth, $user, $phpbb_root_path, $phpEx, $db;
***************
*** 1487,1502 ****
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'thumbnail' => $filedata['thumbnail'],
! 'is_orphan' => 1,
'in_message' => ($is_message) ? 1 : 0,
'poster_id' => $user->data['user_id'],
);
$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$new_entry = array(
'attach_id' => $db->sql_nextid(),
! 'is_orphan' => 1,
'real_filename' => $filedata['real_filename'],
'attach_comment'=> $this->filename_data['filecomment'],
);
--- 1487,1511 ----
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'thumbnail' => $filedata['thumbnail'],
! 'is_orphan' => ($post_msg_id) ? 0 : 1,
'in_message' => ($is_message) ? 1 : 0,
'poster_id' => $user->data['user_id'],
);
+ if ($post_msg_id)
+ {
+ $sql_ary['post_msg_id'] = $post_msg_id;
+ if ($topic_id)
+ {
+ $sql_ary['topic_id'] = $topic_id;
+ }
+ }
+
$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$new_entry = array(
'attach_id' => $db->sql_nextid(),
! 'is_orphan' => ($post_msg_id) ? 0 : 1,
'real_filename' => $filedata['real_filename'],
'attach_comment'=> $this->filename_data['filecomment'],
);
Modified: branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php Fri Jul 24 09:01:29 2009
***************
*** 665,671 ****
}
// Parse Attachments - before checksum is calculated
! $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc))
{
--- 665,686 ----
}
// Parse Attachments - before checksum is calculated
! if ($action == 'edit')
! {
! $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true, $msg_id);
! if (sizeof($message_parser->attachment_data))
! {
! // Update attachment indicators for pms having attachments now, as a precaution if the pm does not get stored by submit
! $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
! SET message_attachment = 1
! WHERE msg_id = ' . $msg_id;
! $db->sql_query($sql);
! }
! }
! else
! {
! $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
! }
if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc))
{
Modified: branches/phpBB-3_0_0/phpBB/posting.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/posting.php (original)
--- branches/phpBB-3_0_0/phpBB/posting.php Fri Jul 24 09:01:29 2009
***************
*** 700,706 ****
}
// Parse Attachments - before checksum is calculated
! $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
// Grab md5 'checksum' of new message
$message_md5 = md5($message_parser->message);
--- 700,727 ----
}
// Parse Attachments - before checksum is calculated
! if ($mode == 'edit')
! {
! $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh, false, $post_id, $topic_id);
! if (sizeof($message_parser->attachment_data))
! {
! // Update attachment indicators for post/topic having attachments now, as a precaution if the post does not get stored by submit
! $sql = 'UPDATE ' . POSTS_TABLE . '
! SET post_attachment = 1
! WHERE post_id = ' . $post_id;
! $db->sql_query($sql);
!
! $sql = 'UPDATE ' . TOPICS_TABLE . '
! SET topic_attachment = 1
! WHERE topic_id = ' . $topic_id;
! $db->sql_query($sql);
! }
! }
! else
! {
! $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
! }
!
// Grab md5 'checksum' of new message
$message_md5 = md5($message_parser->message);
|