Skip to content

Commit 296f6ef

Browse files
committed
Prevent fatal errors when context is missing during migration
1 parent 0790685 commit 296f6ef

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

classes/task/migrate.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ private function convert_to_pluginfile(stdClass $record, string $filecontent): s
182182

183183
switch(helper::get_contextlevel($record, $mapping)) {
184184
case CONTEXT_MODULE:
185-
$context = \context_module::instance($record->instance_id);
185+
$context = \context_module::instance($record->instance_id, IGNORE_MISSING);
186186
break;
187187
case CONTEXT_COURSE:
188-
$context = \context_course::instance($record->instance_id);
188+
$context = \context_course::instance($record->instance_id, IGNORE_MISSING);
189189
break;
190190
// TODO: Implement remaining contexts.
191191
case CONTEXT_USER:
@@ -194,7 +194,8 @@ private function convert_to_pluginfile(stdClass $record, string $filecontent): s
194194
$context = $record->context ?? null;
195195
}
196196

197-
if (!isset($context)) {
197+
// Skip processing of records with missing context.
198+
if (!isset($context) || $context === false) {
198199
return '';
199200
}
200201

0 commit comments

Comments
 (0)