From 7f346ec20c258ac159ae2abae9cca6ab407b3861 Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Thu, 6 Nov 2008 12:27:15 +0000 Subject: [PATCH] MDL-17150: Completion system shouldn't restore data for users who have no access to course --- backup/restorelib.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/backup/restorelib.php b/backup/restorelib.php index 1a422ffa4c..f254d56487 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -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')) { -- 2.39.5