diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index d8a5432113..e9f5994a7c 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -135,6 +135,7 @@
[Fix] Sort backups by date, newest first (Bug #14818)
[Fix] Prevent incomplete backups stored if option "store and download" is selected and admin cancel download by removing the option. (Bug #20325)
[Fix] Enforce correct case for template variables
+ [Fix] Set topic_last_view_time on post/reply/edit to circumvent race conditions in auto prune and false removal of topics for manual forum prune (Bug #18055, #43515)
[Change] Allow download of conflicting file for later reference in automatic updater
[Change] Default difference view is now 'inline' instead of 'side by side'
[Change] Added new option for merging differences to conflicting files in automatic updater
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index e44454b5ff..9b7f8e001f 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -1738,6 +1738,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
$sql_data[TOPICS_TABLE]['sql'] = array(
'topic_poster' => (int) $user->data['user_id'],
'topic_time' => $current_time,
+ 'topic_last_view_time' => $current_time,
'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
'icon_id' => $data['icon_id'],
'topic_approved' => $post_approval,
@@ -1785,7 +1786,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
break;
case 'reply':
- $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');
+ $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ',
+ topic_replies_real = topic_replies_real + 1,
+ topic_bumped = 0,
+ topic_bumper = 0' .
+ (($post_approval) ? ', topic_replies = topic_replies + 1' : '') .
+ ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');
+
$sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : '');
if ($post_approval && $topic_type != POST_GLOBAL)
@@ -1824,6 +1831,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,
'poll_length' => (isset($poll['poll_options'])) ? $poll_length : 0,
'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,
+ 'topic_last_view_time' => $current_time,
'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0),
);
@@ -1867,7 +1875,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
// Correctly set back the topic replies and forum posts... but only if the post was approved before.
if (!$post_approval && $data['post_approved'])
{
- $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1';
+ $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
set_config_count('num_posts', -1, true);