From 9a6f29b019de7f914df84246e656e4c459fd7351 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 13 May 2019 15:03:26 +0800 Subject: [PATCH] MDL-65574 forum: discussion_list vault uses post table for author Update the discussion_list vault to use the first post record from the posts table join to get the author of the first post rather than relying on it's own "userid" column which can be incorrect in the case of split discussions. --- .../classes/local/vaults/discussion_list.php | 4 ++-- .../tests/behat/split_forum_discussion.feature | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mod/forum/classes/local/vaults/discussion_list.php b/mod/forum/classes/local/vaults/discussion_list.php index 9bd2aca9e65..6cfcebf2f58 100644 --- a/mod/forum/classes/local/vaults/discussion_list.php +++ b/mod/forum/classes/local/vaults/discussion_list.php @@ -137,9 +137,9 @@ class discussion_list extends db_table_vault { $issortbyreplies = in_array($sortsql, $sortkeys); $tables = $thistable->get_from_sql(); - $tables .= ' JOIN {user} fa ON fa.id = ' . $alias . '.userid'; - $tables .= ' JOIN {user} la ON la.id = ' . $alias . '.usermodified'; $tables .= ' JOIN ' . $posttable->get_from_sql() . ' ON fp.id = ' . $alias . '.firstpost'; + $tables .= ' JOIN {user} fa ON fa.id = fp.userid'; + $tables .= ' JOIN {user} la ON la.id = ' . $alias . '.usermodified'; $tables .= $favsql; if ($issortbyreplies) { diff --git a/mod/forum/tests/behat/split_forum_discussion.feature b/mod/forum/tests/behat/split_forum_discussion.feature index e664f8a56d9..51bae11ec85 100644 --- a/mod/forum/tests/behat/split_forum_discussion.feature +++ b/mod/forum/tests/behat/split_forum_discussion.feature @@ -9,6 +9,7 @@ Feature: Forum discussions can be split | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | And the following "courses" exist: | fullname | shortname | category | | Science 101 | C1 | 0 | @@ -16,6 +17,7 @@ Feature: Forum discussions can be split | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + | student2 | C1 | student | And I log in as "teacher1" And I am on "Science 101" course homepage with editing mode on And I add a "Forum" to section "1" and I fill the form with: @@ -31,6 +33,16 @@ Feature: Forum discussions can be split And I reply "Photosynethis discussion" post from "Study discussions" forum with: | Message | Can anyone tell me which number is the mass number in the periodic table? | And I log out + And I log in as "student2" + And I am on "Science 101" course homepage + And I follow "Study discussions" + And I follow "Photosynethis discussion" + And I click on "Reply" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' forumpost ')][contains(., 'Can anyone tell me which number is the mass number in the periodic table?')]" "xpath_element" + And I wait to be redirected + And I set the following fields to these values: + | Message | I would also like to know this | + And I press "Post to forum" + And I log out Scenario: Split a forum discussion Given I log in as "teacher1" @@ -44,4 +56,9 @@ Feature: Forum discussions can be split Then I should see "Mass number in periodic table" And I follow "Study discussions" And I should see "Teacher 1" in the "Photosynethis" "table_row" + # Confirm that the last post author has been updated. + And I should not see "Student 2" in the "Photosynethis" "table_row" + # Confirm that the corrent author has been shown for the new split discussion. And I should see "Student 1" in the "Mass number in periodic table" "table_row" + # Confirm that the last post author has been updated for the new discussion. + And I should see "Student 2" in the "Mass number in periodic table" "table_row"