Merge branch 'MDL-63892-master-rework' of git://github.com/mickhawkins/moodle

This commit is contained in:
Andrew Nicols 2019-02-13 10:18:25 +08:00
commit fc9694d1e5
3 changed files with 45 additions and 7 deletions

View File

@ -3126,7 +3126,7 @@ function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring
}
echo '<td class="lastpost">';
$usedate = (empty($post->created)) ? $post->timemodified : $post->created;
$usedate = (empty($post->timemodified)) ? $post->created : $post->timemodified;
$parenturl = '';
$usermodified = new stdClass();
$usermodified->id = $post->usermodified;
@ -3759,10 +3759,6 @@ function forum_update_post($newpost, $mform, $unused = null) {
}
$post->modified = time();
// Last post modified tracking.
$discussion->timemodified = $post->modified;
$discussion->usermodified = $post->userid;
if (!$post->parent) { // Post is a discussion starter - update discussion title and times too
$discussion->name = $post->subject;
$discussion->timestart = $post->timestart;
@ -3775,6 +3771,7 @@ function forum_update_post($newpost, $mform, $unused = null) {
$post->message = file_save_draft_area_files($newpost->itemid, $context->id, 'mod_forum', 'post', $post->id,
mod_forum_post_form::editor_options($context, $post->id), $post->message);
$DB->update_record('forum_posts', $post);
// Note: Discussion modified time/user are intentionally not updated, to enable them to track the latest new post.
$DB->update_record('forum_discussions', $discussion);
forum_add_attachment($post, $forum, $cm, $mform);

View File

@ -593,7 +593,7 @@ file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment'
if ($USER->id != $post->userid) { // Not the original author, so add a message to the end.
$data = new stdClass();
$data->date = userdate($post->modified);
$data->date = userdate($post->created);
if ($post->messageformat == FORMAT_HTML) {
$data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
fullname($USER).'</a>';

View File

@ -3082,6 +3082,17 @@ class mod_forum_lib_testcase extends advanced_testcase {
// On this freshly created discussion, the teacher is the author of the last post.
$this->assertEquals($teacher->id, $DB->get_field('forum_discussions', 'usermodified', ['id' => $discussion->id]));
// Fetch modified timestamp of the discussion.
$discussionmodified = $DB->get_field('forum_discussions', 'timemodified', ['id' => $discussion->id]);
$pasttime = $discussionmodified - 3600;
// Adjust the discussion modified timestamp back an hour, so it's in the past.
$adjustment = (object)[
'id' => $discussion->id,
'timemodified' => $pasttime,
];
$DB->update_record('forum_discussions', $adjustment);
// Let the student reply to the teacher's post.
$reply = $generator->create_post((object)[
'course' => $course->id,
@ -3094,6 +3105,30 @@ class mod_forum_lib_testcase extends advanced_testcase {
// The student should now be the last post's author.
$this->assertEquals($student->id, $DB->get_field('forum_discussions', 'usermodified', ['id' => $discussion->id]));
// Fetch modified timestamp of the discussion and student's post.
$discussionmodified = $DB->get_field('forum_discussions', 'timemodified', ['id' => $discussion->id]);
$postmodified = $DB->get_field('forum_posts', 'modified', ['id' => $reply->id]);
// Discussion modified time should be updated to be equal to the newly created post's time.
$this->assertEquals($discussionmodified, $postmodified);
// Adjust the discussion and post timestamps, so they are in the past.
$adjustment = (object)[
'id' => $discussion->id,
'timemodified' => $pasttime,
];
$DB->update_record('forum_discussions', $adjustment);
$adjustment = (object)[
'id' => $reply->id,
'modified' => $pasttime,
];
$DB->update_record('forum_posts', $adjustment);
// The discussion and student's post time should now be an hour in the past.
$this->assertEquals($pasttime, $DB->get_field('forum_discussions', 'timemodified', ['id' => $discussion->id]));
$this->assertEquals($pasttime, $DB->get_field('forum_posts', 'modified', ['id' => $reply->id]));
// Let the teacher edit the student's reply.
$this->setUser($teacher->id);
$newpost = (object)[
@ -3103,8 +3138,14 @@ class mod_forum_lib_testcase extends advanced_testcase {
];
forum_update_post($newpost, null);
// The student should be still the last post's author.
// The student should still be the last post's author.
$this->assertEquals($student->id, $DB->get_field('forum_discussions', 'usermodified', ['id' => $discussion->id]));
// The discussion modified time should not have changed.
$this->assertEquals($pasttime, $DB->get_field('forum_discussions', 'timemodified', ['id' => $discussion->id]));
// The post time should be updated.
$this->assertGreaterThan($pasttime, $DB->get_field('forum_posts', 'modified', ['id' => $reply->id]));
}
public function test_forum_core_calendar_provide_event_action() {