MDL-17150: Completion system shouldn't restore data for users who have no access to course

This commit is contained in:
sam_marshall 2008-11-06 12:27:15 +00:00
parent 06de498b70
commit 7f346ec20c

View File

@ -1171,7 +1171,17 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
// Now that we have IDs for everything, store any completion data
if($status && !empty($info->completiondata)) {
if($status && !empty($info->completiondata) && count($info->completiondata)>0) {
// Get list of users who can view course (& hence have
// completion data)
if(!isset($restore->userswhocanviewcourse)) {
// Because this is only used here, there is no point requesting
// anything except id
$restore->userswhocanviewcourse=get_users_by_capability(
get_context_instance(CONTEXT_COURSE, $restore->course_id),
'moodle/course:view','u.id');
}
foreach($info->completiondata as $data) {
// Convert cmid
$newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->coursemoduleid);
@ -1195,6 +1205,15 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
continue;
}
// Check user is still able to access new course (they
// might have had their role assignment excluded, and it
// creates arguably bogus database rows if we add completion
// data for them, and displays confusingly in the 'number
// of people who have already marked this complete' UI)
if(!array_key_exists($data->userid,$restore->userswhocanviewcourse)) {
continue;
}
// Add record
if(!$DB->insert_record('course_modules_completion',$data)) {
if (!defined('RESTORE_SILENTLY')) {