Skip to content

Commit a8d7e86

Browse files
committed
MD-1661: Forum calendar update fix (PR moodleou#40)
Add save_dates() override to report_editdates_mod_forum_date_extractor that calls forum_update_calendar() and forum_grade_item_update() after saving dates to the DB, so calendar events reflect the new dates. Also queue a refresh_mod_calendar_events_task adhoc task in index.php after rebuild_course_cache() to refresh all module calendar events for the course in bulk. Ref: moodleou#40 (commit b5508f9) Made-with: Cursor
1 parent 96fc7e8 commit a8d7e86

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@
214214
// Commit transaction and finish up.
215215
$transaction->allow_commit();
216216
rebuild_course_cache($course->id);
217+
// BEGIN LSU MD-1661: Queue adhoc task to refresh all mod calendar events after date update
218+
// See: https://github.com/moodleou/moodle-report_editdates/pull/40 (commit b5508f9)
219+
$task = new \core\task\refresh_mod_calendar_events_task();
220+
$task->set_custom_data(['courseid' => $course->id]);
221+
\core\task\manager::queue_adhoc_task($task, true);
222+
// END LSU MD-1661: Queue adhoc task to refresh all mod calendar events after date update
217223
redirect($PAGE->url, get_string('changessaved'));
218224
}
219225

mod/forumdates.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,23 @@ public function validate_dates(cm_info $cm, array $dates) {
8181
}
8282
return $errors;
8383
}
84+
85+
// BEGIN LSU MD-1661: Call forum_update_calendar and forum_grade_item_update after saving dates
86+
// See: https://github.com/moodleou/moodle-report_editdates/pull/40 (commit b5508f9)
87+
// Without this override the forum's calendar events remain stale after dates are updated
88+
// via this report, because the base save_dates() only does a DB update_record().
89+
#[\Override]
90+
public function save_dates(cm_info $cm, array $dates) {
91+
global $DB, $CFG;
92+
parent::save_dates($cm, $dates);
93+
94+
require_once($CFG->dirroot . '/mod/forum/locallib.php');
95+
$forum = $DB->get_record('forum', ['id' => $cm->instance]);
96+
$forum->cmidnumber = $cm->id;
97+
98+
// Update the calendar events and grade item for this forum.
99+
forum_update_calendar($forum, $cm->id);
100+
forum_grade_item_update($forum);
101+
}
102+
// END LSU MD-1661: Call forum_update_calendar and forum_grade_item_update after saving dates
84103
}

0 commit comments

Comments
 (0)