Skip to content

Commit

Permalink
Merge branch 'MDL-72991-master-4' of https://github.com/HuongNV13/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 17, 2022
2 parents 08bae4c + bfe14e2 commit 27bed0b
Show file tree
Hide file tree
Showing 21 changed files with 698 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,58 @@ Feature: availability_completion
# Mark page 1 complete
When I toggle the manual completion state of "Page 1"
Then I should see "Page 2" in the "region-main" "region"

@javascript
Scenario: Test completion and course cache rebuild
Given the following "activities" exist:
| activity | name | intro | course | idnumber |
| forum | forum 1 | forum 1 | C1 | forum1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I open "forum 1" actions menu
And I click on "Edit settings" "link" in the "forum 1" activity
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| completionview | 1 |
| completionpostsenabled | 1 |
| completionposts | 2 |
And I press "Save and return to course"
And I add a new discussion to "forum 1" forum with:
| Subject | Forum post 1 |
| Message | This is the body |
And I am on "Course 1" course homepage with editing mode on
And I add a "Page" to section "2"
And I set the following fields to these values:
| Name | Page 2 |
| Description | Test |
| Page content | Test |
And I expand all fieldsets
And I press "Add restriction..."
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I click on ".availability-item .availability-eye img" "css_element"
And I set the following fields to these values:
| Required completion status | must be marked complete |
| cm | forum 1 |
And I press "Save and return to course"
And I log out
And I log in as "student1"
When I am on "Course 1" course homepage
# Page 2 should not appear yet.
Then I should not see "Page 2" in the "region-main" "region"
And I click on "forum 1" "link" in the "region-main" "region"
# Page 2 should not appear yet.
And I should not see "Page 2" in the "region-main" "region"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I am on the "forum 1" "forum activity editing" page
And I expand all fieldsets
And I set the following fields to these values:
| completionpostsenabled | 0 |
And I press "Save and display"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I click on "forum 1" "link" in the "region-main" "region"
And I am on "Course 1" course homepage
And I should see "Page 2" in the "region-main" "region"
6 changes: 4 additions & 2 deletions availability/condition/date/classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,16 @@ public static function update_all_dates($courseid, $timeshift) {
$updatesection->availability = json_encode($tree->save());
$updatesection->timemodified = time();
$DB->update_record('course_sections', $updatesection);
// Invalidate the section cache by given section id.
\course_modinfo::purge_course_section_cache_by_id($courseid, $section->id);

$anychanged = true;
}
}

// Ensure course cache is cleared if required.
if ($anychanged) {
rebuild_course_cache($courseid, true);
// Partial rebuild the sections which have been invalidated.
rebuild_course_cache($courseid, true, true);
}
}
}
4 changes: 3 additions & 1 deletion course/dnduploadlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,10 @@ protected function finish_setup_course_module($instanceid) {
$visible = get_fast_modinfo($this->course)->get_section_info($this->section)->visible;

$DB->set_field('course_modules', 'instance', $instanceid, array('id' => $this->cm->id));

\course_modinfo::purge_course_module_cache($this->course->id, $this->cm->id);
// Rebuild the course cache after update action
rebuild_course_cache($this->course->id, true);
rebuild_course_cache($this->course->id, true, true);

$sectionid = course_add_cm_to_section($this->course, $this->cm->id, $this->section);

Expand Down
15 changes: 13 additions & 2 deletions course/format/classes/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,15 @@ protected function update_format_options($data, $sectionid = null) {
}
}
if ($needrebuild) {
rebuild_course_cache($this->courseid, true);
if ($sectionid) {
// Invalidate the section cache by given section id.
course_modinfo::purge_course_section_cache_by_id($this->courseid, $sectionid);
// Partial rebuild sections that have been invalidated.
rebuild_course_cache($this->courseid, true, true);
} else {
// Full rebuild if sectionid is null.
rebuild_course_cache($this->courseid);
}
}
if ($changed) {
// Reset internal caches.
Expand Down Expand Up @@ -1422,7 +1430,10 @@ public function delete_section($section, $forcedeleteifnotempty = false) {
// Delete section and it's format options.
$DB->delete_records('course_format_options', array('sectionid' => $section->id));
$DB->delete_records('course_sections', array('id' => $section->id));
rebuild_course_cache($course->id, true);
// Invalidate the section cache by given section id.
course_modinfo::purge_course_section_cache_by_id($course->id, $section->id);
// Partial rebuild section cache that has been purged.
rebuild_course_cache($course->id, true, true);

// Delete section summary files.
$context = \context_course::instance($course->id);
Expand Down
Loading

0 comments on commit 27bed0b

Please sign in to comment.