From 613582e2c5bda7b9fc4b75598d7696ff8f4a681e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 9 Nov 2023 21:08:31 +0100 Subject: [PATCH 1/3] [ticket/17212] Support updating session info when editing post with p= PHPBB3-17212 --- phpBB/phpbb/session.php | 2 +- phpBB/posting.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index df88a849df..43f96c90af 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -1759,7 +1759,7 @@ class session } // Do not update the session page for ajax requests, so the view online still works as intended - $page_changed = $this->update_session_page && (!isset($this->data['session_page']) || $this->data['session_page'] != $this->page['page']) && !$request->is_ajax(); + $page_changed = $this->update_session_page && (!isset($this->data['session_page']) || $this->data['session_page'] != $this->page['page'] || $this->data['session_forum_id'] != $this->page['forum']) && !$request->is_ajax(); // Only update session DB a minute or so after last update or if page changes if ($this->time_now - (isset($this->data['session_time']) ? $this->data['session_time'] : 0) > 60 || $page_changed) diff --git a/phpBB/posting.php b/phpBB/posting.php index 736812cfaf..e188da8ffb 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -104,8 +104,16 @@ switch ($mode) trigger_error('NO_POST'); } + if (!$forum_id) + { + $user->page['forum'] = (int) $topic_forum['forum_id']; + $user->update_session_page = true; + $user->update_session_infos(); + } + $topic_id = (int) $topic_forum['topic_id']; $forum_id = (int) $topic_forum['forum_id']; + break; } From c0984686999985d9e9a1a7bf8575cab190018fbf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 9 Nov 2023 21:10:07 +0100 Subject: [PATCH 2/3] [ticket/17212] Add comment on the need for updating session info PHPBB3-17212 --- phpBB/posting.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index e188da8ffb..724d8a8df1 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -104,6 +104,7 @@ switch ($mode) trigger_error('NO_POST'); } + // Need to update session forum_id to valid value for proper viewonline information if (!$forum_id) { $user->page['forum'] = (int) $topic_forum['forum_id']; From 92e678a116252f18426a1dab48a3056d95e3ffc4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 11 Nov 2023 10:36:17 +0100 Subject: [PATCH 3/3] [ticket/17212] Extend viewonline test for editing post PHPBB3-17212 --- tests/functional/viewonline_test.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/functional/viewonline_test.php b/tests/functional/viewonline_test.php index 871d43792d..882c48a5e1 100644 --- a/tests/functional/viewonline_test.php +++ b/tests/functional/viewonline_test.php @@ -38,7 +38,7 @@ class phpbb_functional_viewonline_test extends phpbb_functional_test_case // Forum info $sql = 'SELECT forum_name - FROM ' . FORUMS_TABLE . ' + FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . (int) $forum_id; $result = $db->sql_query($sql); $forum_name = $db->sql_fetchfield('forum_name'); @@ -81,6 +81,22 @@ class phpbb_functional_viewonline_test extends phpbb_functional_test_case $this->assertStringContainsString('viewonline-test-user1', $crawler->text()); $this->assertStringContainsString($this->lang('POSTING_MESSAGE', $this->get_forum_name_by_forum_id(2)), $crawler->text()); + // Log in as test user + self::$client->restart(); + $this->login('viewonline-test-user1'); + $test_post_data = $this->create_post(2, 1, 'Viewonline test post #1', 'Viewonline test post message'); + $crawler = self::request('GET', 'posting.php?mode=edit&p=' . $test_post_data['post_id'] . '&sid=' . $this->sid); + $this->assertContainsLang('EDIT_POST', $crawler->text()); + // Log in as another user + self::$client->restart(); + $this->login(); + // PHP goes faster than DBMS, make sure session data got written to the database + sleep(1); + $crawler = self::request('GET', 'viewonline.php?sid=' . $this->sid); + // Make sure posting message page is in the list + $this->assertStringContainsString('viewonline-test-user1', $crawler->text()); + $this->assertStringContainsString($this->lang('POSTING_MESSAGE', $this->get_forum_name_by_forum_id(2)), $crawler->text()); + // Log in as test user self::$client->restart(); $this->login('viewonline-test-user1');