]> git.mjollnir.org Git - moodle.git/commitdiff
Solved two possibe bugs:
authorstronk7 <stronk7>
Mon, 22 Sep 2003 08:30:22 +0000 (08:30 +0000)
committerstronk7 <stronk7>
Mon, 22 Sep 2003 08:30:22 +0000 (08:30 +0000)
    - Restoring to courses without section 0 (manually deleted).
    - Restoring to sections without mods and null values in its sequence field.
Thanks to Janne Mikkonen...

backup/restorelib.php

index 6c19bfcfadd738498a80b6331e81dea3d6532b0b..2590a5b22bf14e7927a2665a718987db25647c33 100644 (file)
                         $rec = get_record("course_sections","course",$restore->course_id,
                                                             "section","0");
                     }
+                    //New check. If section 0 doesn't exist, insert it here !!
+                    //Teorically this never should happen but, in practice, some users
+                    //have reported this issue. 
+                    if(!$rec) {
+                        $zero_sec->course = $restore->course_id;
+                        $zero_sec->section = 0;
+                        $zero_sec->summary = "";
+                        $zero_sec->sequence = "";
+                        $newid = insert_record("course_sections",$zero_sec);
+                        $rec->id = $newid;
+                        $rec->sequence = "";
+                    }
                     $newid = $rec->id;
                     $sequence = $rec->sequence;
                 }
                 }
                 //If all is OK, update sequence field in course_sections
                 if ($status) {
-                    $rec->id = $newid;
-                    $rec->sequence = $sequence;
-                    //Unset other fields before update (we don't want them)
-                    //Only need id and sequence !! Previously, existing bug 
-                    //because update without addslashes in summary
-                    unset($rec->course);
-                    unset($rec->section);
-                    unset($rec->summary);
-                    unset($rec->visible);
-                    $status = update_record("course_sections",$rec);
+                    if (isset($sequence)) {
+                        $update_rec->id = $newid;
+                        $update_rec->sequence = $sequence;
+                        $status = update_record("course_sections",$update_rec);
+                    }
                 }
             }
         } else {