Skip to content

Commit

Permalink
Merge branch 'MDL-74698' of https://github.com/jonof/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 16, 2023
2 parents 26af3bc + d9bc9af commit 18073fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,11 @@ protected function define_structure() {
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());
Expand Down
12 changes: 11 additions & 1 deletion backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,10 @@ public function process_course($data) {
// 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());
}
Expand Down Expand Up @@ -1989,8 +1993,14 @@ public function process_customfield($data) {
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 {
Expand Down

0 comments on commit 18073fe

Please sign in to comment.