Skip to content

Commit

Permalink
MDL-21432 backup - improve section target detection on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 28, 2010
1 parent b61b4ed commit aa39be2
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,29 @@ protected function process_module($data) {

$data->course = $this->task->get_courseid();
$data->module = $DB->get_field('modules', 'id', array('name' => $data->modulename));
$data->section = $this->get_mappingid('course_section', $data->sectionid); // map section
// Map section (first try by course_section mapping match. Useful in course and section restores)
$data->section = $this->get_mappingid('course_section', $data->sectionid);
if (!$data->section) { // mapping failed, try to get section by sectionnumber matching
$params = array(
'course' => $this->get_courseid(),
'section' => $data->sectionnumber);
$data->section = $DB->get_field('course_sections', 'id', $params);
}
if (!$data->section) { // sectionnumber failed, try to get first section in course
$params = array(
'course' => $this->get_courseid());
$data->section = $DB->get_field('course_sections', 'MIN(id)', $params);
}
if (!$data->section) { // no sections in course, create section 0 and 1 and assign module to 1
$sectionrec = array(
'course' => $this->get_courseid(),
'section' => 0);
$DB->insert_record('course_sections', $sectionrec); // section 0
$sectionrec = array(
'course' => $this->get_courseid(),
'section' => 1);
$data->section = $DB->insert_record('course_sections', $sectionrec); // section 1
}
$data->groupingid= $this->get_mappingid('grouping', $data->groupingid); // grouping
if (!$CFG->enablegroupmembersonly) { // observe groupsmemberonly
$data->groupmembersonly = 0;
Expand Down

0 comments on commit aa39be2

Please sign in to comment.