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.
This commit is contained in:
Ryan Wyllie 2019-05-13 15:03:26 +08:00
parent 6a7451ff1b
commit 9a6f29b019
2 changed files with 19 additions and 2 deletions

View File

@ -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) {

View File

@ -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"