Merge branch 'MDL-74698_401' of https://github.com/jonof/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols 2023-02-16 11:06:44 +08:00
commit 41c1731431
2 changed files with 14 additions and 2 deletions

View File

@ -546,9 +546,11 @@ class backup_course_structure_step extends backup_structure_step {
backup_helper::is_sqlparam('course'),
backup::VAR_PARENTID));
// Section level settings are dealt with in backup_section_structure_step.
// We only need to deal with course level (sectionid = 0) here.
$courseformatoption->set_source_sql('SELECT id, format, sectionid, name, value
FROM {course_format_options}
WHERE courseid = ?', [ backup::VAR_PARENTID ]);
WHERE courseid = ? AND sectionid = 0', [ backup::VAR_PARENTID ]);
$handler = core_course\customfield\course_handler::create();
$fieldsforbackup = $handler->get_instance_data_for_backup($this->task->get_courseid());

View File

@ -1952,6 +1952,10 @@ class restore_course_structure_step extends restore_structure_step {
// Course record ready, update it
$DB->update_record('course', $data);
// Apply any course format options that may be saved against the course
// entity in earlier-version backups.
course_get_format($data)->update_course_format_options($data);
// Role name aliases
restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
}
@ -1989,8 +1993,14 @@ class restore_course_structure_step extends restore_structure_step {
public function process_course_format_option(array $data) : void {
global $DB;
if ($data['sectionid']) {
// Ignore section-level format options saved course-level in earlier-version backups.
return;
}
$courseid = $this->get_courseid();
$record = $DB->get_record('course_format_options', [ 'courseid' => $courseid, 'name' => $data['name'] ], 'id');
$record = $DB->get_record('course_format_options', [ 'courseid' => $courseid, 'name' => $data['name'],
'format' => $data['format'], 'sectionid' => 0 ], 'id');
if ($record !== false) {
$DB->update_record('course_format_options', (object) [ 'id' => $record->id, 'value' => $data['value'] ]);
} else {