]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17150: Completion system shouldn't restore data for users who have no access...
authorsam_marshall <sam_marshall>
Thu, 6 Nov 2008 12:27:15 +0000 (12:27 +0000)
committersam_marshall <sam_marshall>
Thu, 6 Nov 2008 12:27:15 +0000 (12:27 +0000)
backup/restorelib.php

index 1a422ffa4cbc3d806b4d2aa6cb5b3fb3d7aacda0..f254d56487f054e569ec2122b074bf9b3988e157 100644 (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')) {