From: stronk7 Date: Wed, 28 May 2003 23:41:56 +0000 (+0000) Subject: Changed bahabior when restoring into a existing course X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=64eed73fa2319bde129d6ada4e43020ab052f2a0;p=moodle.git Changed bahabior when restoring into a existing course (don't create sections and assign to section 0 if original section doesn't exist). Everything is saved in backup_ids to use it when restoring modules. --- diff --git a/backup/restore_execute.html b/backup/restore_execute.html index 0563a57186..45b9ea3542 100644 --- a/backup/restore_execute.html +++ b/backup/restore_execute.html @@ -63,11 +63,19 @@ } //Now create the course_sections and their associated course_modules - if (($restore->restoreto ==1) and ($status)) { - echo "
  • Creating sections"; - $status = restore_create_sections($restore,$xml_file); + if ($status) { + if ($restore->restoreto == 1) { + echo "
  • Creating sections"; + $status = restore_create_sections($restore,$xml_file); + } else if ($restore->restoreto == 0) { + echo "
  • Checking sections"; + $status = restore_create_sections($restore,$xml_file); + } else { + $status = false; + } } + //Now create users as needed if ($status and ($restore->users == 0 or $restore->users == 1)) { echo "
  • Creating users"; diff --git a/backup/restorelib.php b/backup/restorelib.php index 0526fbde1c..5922b38857 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -288,9 +288,11 @@ } //This function creates all the course_sections and course_modules from xml + //when restoring in a new course or simply checks sections and create records + //in backup_ids when restoring in a existing course function restore_create_sections($restore,$xml_file) { - global $CFG; + global $CFG,$db; $status = true; //Check it exists @@ -314,8 +316,24 @@ $section->summary = $sect->summary; $section->visible = $sect->visible; $section->sequence = ""; - //Save it to db - $newid = insert_record("course_sections",$section); + //Now calculate the section's newid + $newid = 0; + if ($restore->restoreto == 1) { + //Save it to db (only if restoring to new course) + $newid = insert_record("course_sections",$section); + } else { + //Get section id when restoring in existing course + $rec = get_record("course_sections","course",$restore->course_id, + "section",$section->section); + //If that section doesn't exist, get section 0 (every mod will be + //asigned there + if(!$rec) { + $rec = get_record("course_sections","course",$restore->course_id, + "section","0"); + } + $newid = $rec->id; + $sequence = $rec->sequence; + } if ($newid) { //save old and new section id backup_putid ($restore->backup_unique_code,"course_sections",$key,$newid); @@ -375,7 +393,6 @@ } else { $status = false; } - return $status; } @@ -870,6 +887,7 @@ $this->info->sections[$this->info->tempsection->id]->number = $this->info->tempsection->number; $this->info->sections[$this->info->tempsection->id]->summary = $this->info->tempsection->summary; $this->info->sections[$this->info->tempsection->id]->visible = $this->info->tempsection->visible; + $this->info->sections[$this->info->tempsection->id]->mods = $this->info->tempsection->mods; unset($this->info->tempsection); } }