aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/docs/CHANGELOG.html1
-rw-r--r--phpBB/includes/functions_admin.php58
-rw-r--r--phpBB/includes/functions_posting.php15
-rw-r--r--phpBB/includes/message_parser.php15
-rw-r--r--phpBB/includes/ucp/ucp_pm_compose.php17
-rw-r--r--phpBB/posting.php23
6 files changed, 116 insertions, 13 deletions
diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index afba5d32f3..cf1e7a24cc 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -174,6 +174,7 @@
<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>
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index ff7f687945..457fac2458 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -892,19 +892,61 @@ function delete_attachments($mode, $ids, $resync = true)
// 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);
+ // 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))
{
- $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
- SET message_attachment = 0
- WHERE ' . $db->sql_in_set('msg_id', $message_ids);
- $db->sql_query($sql);
+ // 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
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 7db2875cda..e348694cfe 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -1549,6 +1549,21 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
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');
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 7370c2057c..7a2d35dbc6 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -1334,7 +1334,7 @@ class parse_message extends bbcode_firstpass
/**
* Parse Attachments
*/
- function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
+ 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,16 +1487,25 @@ class parse_message extends bbcode_firstpass
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'thumbnail' => $filedata['thumbnail'],
- 'is_orphan' => 1,
+ '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' => 1,
+ 'is_orphan' => ($post_msg_id) ? 0 : 1,
'real_filename' => $filedata['real_filename'],
'attach_comment'=> $this->filename_data['filecomment'],
);
diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php
index edee64bd18..cf82925e1d 100644
--- a/phpBB/includes/ucp/ucp_pm_compose.php
+++ b/phpBB/includes/ucp/ucp_pm_compose.php
@@ -665,7 +665,22 @@ function compose_pm($id, $mode, $action)
}
// Parse Attachments - before checksum is calculated
- $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
+ 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))
{
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 600bf1688c..d304168153 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -700,7 +700,28 @@ if ($submit || $preview || $refresh)
}
// Parse Attachments - before checksum is calculated
- $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
+ 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);