MDL-73671 mod_forum: shift activity due/cutoff dates during reset.
This commit is contained in:
@@ -5006,7 +5006,7 @@ function forum_reset_gradebook($courseid, $type='') {
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @param $data the data submitted from the reset course.
|
||||
* @param stdClass $data the data submitted from the reset course.
|
||||
* @return array status array
|
||||
*/
|
||||
function forum_reset_userdata($data) {
|
||||
@@ -5209,7 +5209,13 @@ function forum_reset_userdata($data) {
|
||||
if ($data->timeshift) {
|
||||
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
|
||||
// See MDL-9367.
|
||||
shift_course_mod_dates('forum', ['assesstimestart', 'assesstimefinish'], $data->timeshift, $data->courseid);
|
||||
shift_course_mod_dates('forum', [
|
||||
'assesstimestart',
|
||||
'assesstimefinish',
|
||||
'duedate',
|
||||
'cutoffdate',
|
||||
], $data->timeshift, $data->courseid);
|
||||
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('date'),
|
||||
|
||||
@@ -4285,4 +4285,34 @@ final class lib_test extends \advanced_testcase {
|
||||
$f3discussionscount = forum_count_discussions($forum3, $forum3cm, $course2);
|
||||
$this->assertEquals(0, $f3discussionscount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::forum_reset_userdata
|
||||
*/
|
||||
public function test_forum_reset_userdata(): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$now = time();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$forum = $this->getDataGenerator()->create_module('forum', [
|
||||
'course' => $course->id,
|
||||
'duedate' => $now + HOURSECS,
|
||||
'cutoffdate' => $now + DAYSECS,
|
||||
]);
|
||||
|
||||
forum_reset_userdata((object) [
|
||||
'courseid' => $course->id,
|
||||
'timeshift' => DAYSECS * 2,
|
||||
]);
|
||||
|
||||
// Reload the instance data.
|
||||
$instance = $DB->get_record('forum', ['id' => $forum->id]);
|
||||
|
||||
$this->assertEquals($forum->duedate + (DAYSECS * 2), $instance->duedate);
|
||||
$this->assertEquals($forum->cutoffdate + (DAYSECS * 2), $instance->cutoffdate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user