Skip to content

Commit

Permalink
MDL-46960 completion: trigger event after clearing cache
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy authored and stronk7 committed Apr 2, 2015
1 parent 345c6a1 commit f797471
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/completionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ public function get_data($cm, $wholecourse = false, $userid = 0, $modinfo = null
}

// Not there, get via SQL
if ($wholecourse) {
if ($usecache && $wholecourse) {
// Get whole course data for cache
$alldatabycmc = $DB->get_records_sql("
SELECT
Expand Down Expand Up @@ -1019,18 +1019,6 @@ public function internal_set_data($cm, $data) {
$cmcontext = context_module::instance($data->coursemoduleid, MUST_EXIST);
$coursecontext = $cmcontext->get_parent_context();

// Trigger an event for course module completion changed.
$event = \core\event\course_module_completion_updated::create(array(
'objectid' => $data->id,
'context' => $cmcontext,
'relateduserid' => $data->userid,
'other' => array(
'relateduserid' => $data->userid
)
));
$event->add_record_snapshot('course_modules_completion', $data);
$event->trigger();

$completioncache = cache::make('core', 'completion');
if ($data->userid == $USER->id) {
// Update module completion in user's cache.
Expand All @@ -1047,6 +1035,18 @@ public function internal_set_data($cm, $data) {
// Remove another user's completion cache for this course.
$completioncache->delete($data->userid . '_' . $cm->course);
}

// Trigger an event for course module completion changed.
$event = \core\event\course_module_completion_updated::create(array(
'objectid' => $data->id,
'context' => $cmcontext,
'relateduserid' => $data->userid,
'other' => array(
'relateduserid' => $data->userid
)
));
$event->add_record_snapshot('course_modules_completion', $data);
$event->trigger();
}

/**
Expand Down

0 comments on commit f797471

Please sign in to comment.