-
Bug
-
Resolution: Fixed
-
Minor
-
4.3.9, 4.4.1
Stumble upon this issue when using course reuse/restore to restore the backup into a new course. Existing backup course utilised the custom data fields. Backup is working as expected, however trying to restore the course throw some errors where the course is pending for restore.
I tried to identify the problem. When choosing the restore options, I can see the course entry created in mdl_course table in the db.
For example
ID: 2903
Fullname: Course restoration in progress copy 1
All is well, until when i click "perform restore". The entry is delete from the mdl_course table. And then I get this error:
dml_missing_record_exception
Can't find data record in database table course. (SELECT id,category FROM {course} WHERE id = ? [array ( 0 => 8432, )])
The ID 8432 seems out of place, as the created new course ID should have been 2903, as per the example above. Upon checking further 8432 seems to be the latest id for an entry in mdl_customfield_data. I am using 4 custom fields in my courses for various meta details. For some reason the backup tool is refering to the wrong ID.
Further drill down leads to line 2019, in this particular file backup\moodle2\restore_stepslib.php the function restore_instance_data_from_backup that is causing the issue.
public function process_customfield($data) {
$handler = core_course\customfield\course_handler::create();
$newid = $handler->restore_instance_data_from_backup($this->task, $data);
if ($newid)
{ $handler->restore_define_structure($this, $newid, $data['id']); }}
The file course/classes/customfield/course_handler.php the function restore_instance_data_from_backup seems to return the first custom field data id straightaway as the course id.
public function restore_instance_data_from_backup(\restore_task $task, array $data) {
$courseid = $task->get_courseid();
$context = $this->get_instance_context($courseid);
$editablefields = $this->get_editable_fields($courseid);
$records = api::get_instance_fields_data($editablefields, $courseid);
$target = $task->get_target();
$override = ($target != \backup::TARGET_CURRENT_ADDING && $target != \backup::TARGET_EXISTING_ADDING);
foreach ($records as $d) {
$field = $d->get_field();
if ($field->get('shortname') === $data['shortname'] && $field->get('type') === $data['type']) {
if (!$d->get('id') || $override)
return $d->get('id');
}
}
}
Stack trace
Can't find data record in database table course.
|
|
More information about this error
|
Debug info: SELECT id,category FROM {course} WHERE id = ?
|
[array (
|
0 => 3,
|
)]
|
Error code: invalidrecord
|
Stack trace:
|
|
line 1662 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
|
line 1638 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
|
line 200 of /lib/classes/context/course.php: call to moodle_database->get_record()
|
line 185 of /course/classes/customfield/course_handler.php: call to core\context\course::instance()
|
line 127 of /course/classes/customfield/course_handler.php: call to core_course\customfield\course_handler->get_instance_context()
|
line 785 of /customfield/classes/handler.php: call to core_course\customfield\course_handler->can_view()
|
line ? of unknownfile: call to core_customfield\handler->core_customfield\{closure}()
|
line 786 of /customfield/classes/handler.php: call to array_filter()
|
line 377 of /customfield/classes/handler.php: call to core_customfield\handler->get_visible_fields()
|
line 524 of /customfield/classes/handler.php: call to core_customfield\handler->get_instance_data()
|
line 2104 of /backup/moodle2/restore_stepslib.php: call to core_customfield\handler->restore_define_structure()
|
line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_course_structure_step->process_customfield()
|
line 123 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
|
line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
|
line 111 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
|
line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
|
line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
|
line 189 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
|
line 277 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
|
line ? of unknownfile: call to progressive_parser->end_tag()
|
line 178 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
|
line 157 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
|
line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
|
line 199 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
|
line 191 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
|
line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
|
line 411 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
|
line 219 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()
|
line 146 of /backup/restore.php: call to restore_ui->execute()
|
- has been marked as being related by
-
MDL-80929 Backup/restore "Include custom fields" setting is not observed
-
- Closed
-
-
MDL-82220 Error "Can't find data record in database table groups" when restoring activity to the other site using group custom field.
-
- Closed
-
-
MDL-79151 Backup of custom fields for courses should include images
-
- Closed
-
- is duplicated by
-
MDL-83326 Restoring courses with custom fields breaks when visibility is Teachers
-
- Closed
-
- links to