diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index 4c2471ab92..18fb050a75 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -1663,7 +1663,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 bb43a349f2..79ba5585e9 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -104,8 +104,17 @@ 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']; + $user->update_session_page = true; + $user->update_session_infos(); + } + $topic_id = (int) $topic_forum['topic_id']; $forum_id = (int) $topic_forum['forum_id']; + break; } 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');