MDL-63665 mod_choice: no exception when course_modules doesn't exist
authorShamim Rezaie <shamim@moodle.com>
Wed, 17 Oct 2018 06:19:58 +0000 (17:19 +1100)
committerShamim Rezaie <shamim@moodle.com>
Fri, 26 Oct 2018 07:48:10 +0000 (18:48 +1100)
This issue is a part of the MDL-62560 Epic.

mod/choice/classes/privacy/provider.php

index 46eb902..353ba0a 100644 (file)
@@ -244,7 +244,10 @@ class provider implements
             if (!$context instanceof \context_module) {
                 continue;
             }
-            $instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
+            $instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid]);
+            if (!$instanceid) {
+                continue;
+            }
             $DB->delete_records('choice_answers', ['choiceid' => $instanceid, 'userid' => $userid]);
         }
     }