From: stronk7 Date: Mon, 22 Sep 2003 08:30:22 +0000 (+0000) Subject: Solved two possibe bugs: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bd96236e868a6ee1d2e1e3a9d96c18bbb65e31bb;p=moodle.git Solved two possibe bugs: - Restoring to courses without section 0 (manually deleted). - Restoring to sections without mods and null values in its sequence field. Thanks to Janne Mikkonen... --- diff --git a/backup/restorelib.php b/backup/restorelib.php index 6c19bfcfad..2590a5b22b 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -368,6 +368,18 @@ $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; } @@ -428,16 +440,11 @@ } //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 {