]> git.mjollnir.org Git - moodle.git/commitdiff
Changed bahabior when restoring into a existing course
authorstronk7 <stronk7>
Wed, 28 May 2003 23:41:56 +0000 (23:41 +0000)
committerstronk7 <stronk7>
Wed, 28 May 2003 23:41:56 +0000 (23:41 +0000)
(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.

backup/restore_execute.html
backup/restorelib.php

index 0563a57186b500bb5113cb6042bdf7c3499d649a..45b9ea3542172550728a3dc4c13e74edc3c421e3 100644 (file)
     }
 
     //Now create the course_sections and their associated course_modules
-    if (($restore->restoreto ==1) and ($status)) {
-        echo "<li>Creating sections";
-        $status = restore_create_sections($restore,$xml_file);
+    if ($status) {
+        if ($restore->restoreto == 1) {
+            echo "<li>Creating sections";
+            $status = restore_create_sections($restore,$xml_file);
+        } else if ($restore->restoreto == 0) {
+            echo "<li>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 "<li>Creating users";
index 0526fbde1c6e1ff51dfe821b22c6ce52c5510591..5922b388571658e486d1b28f3e9778b568dcebee 100644 (file)
     }
 
     //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
                 $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);
         } else {
             $status = false;
         }
-
         return $status;
     }
     
                             $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);
                     }
                 }