-
Bug
-
Resolution: Fixed
-
Minor
-
3.9.3, 3.10
-
MOODLE_310_STABLE, MOODLE_39_STABLE
-
MOODLE_310_STABLE, MOODLE_39_STABLE
-
MDL-70261-master -
-
Moppies Kanban
Steps to reproduce:
- Visit /course/customfield.php. Create a new custom field.
- Edit the custom field, set "Locked" = "Yes".
- Visit /admin/tool/uploadcourse/index.php
- Upload a simple course CSV, e.g:
-
shortname,fullname,category
test1,Test 1,1
- Click "Preview". You should get an error: "Coding error detected, it must be fixed by a programmer: Only course or course category context expected"
This error is caused by incorrect assumptions in /course/classes/customfield/course_handler.php, in the can_edit function:
return (!$field->get_configdata_property('locked') || guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context)); |
|
When uploading a course, $context will always be an instance of context_system, because the caller passes $instanceid = 0. The function guess_if_creator_will_have_course_capability does not allow $context to be a context_system instance. So if the field in question is locked, that function is called with a context_system instance and a coding error is thrown.