diff --git a/backup/CHANGES_14_15.txt b/backup/CHANGES_14_15.txt index d52b4572d83..f45f4ea8259 100644 --- a/backup/CHANGES_14_15.txt +++ b/backup/CHANGES_14_15.txt @@ -30,8 +30,9 @@ Now I show the specific detailed status of every item in the process: teacher in the restored course. See bug 2381. 19. DONE: Move blocks code to libraries and use it in a standard way. Now new blocks are supported by scheduled backup. -20. TODO: Review the lesson module completely! Check the upgrade process to - mimic it. +20. PROG: Review the lesson module completely! Check the upgrade process to + mimic it. Pending to decide if the grade field must go to the score + one when restoring old files!! (sent to Michael, Mark and Martin). 21. TODO: Review the workshop module completely! Check the upgrade process to mimic it. 22. PROG: Review the wiki module fully. Now the wiki backup & restore seems to diff --git a/backup/version.php b/backup/version.php index 098fb7575e1..de253040777 100644 --- a/backup/version.php +++ b/backup/version.php @@ -5,6 +5,6 @@ // database (backup_version) to determine whether upgrades should // be performed (see db/backup_*.php) -$backup_version = 2005021800; // The current version is a date (YYYYMMDDXX) +$backup_version = 2005030600; // The current version is a date (YYYYMMDDXX) $backup_release = "1.5 development"; // User-friendly version number diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index de45b00b82c..317ad30f82c 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -74,7 +74,7 @@ fwrite ($bf,full_tag("HEIGHT",4,false,$lesson->height)); fwrite ($bf,full_tag("BGCOLOR",4,false,$lesson->bgcolor)); fwrite ($bf,full_tag("DISPLAYLEFT",4,false,$lesson->displayleft)); - fwrite ($bf,full_tag("HIGHSCORES",4,false,$lesson->highscores)); + fwrite ($bf,full_tag("SHOWHIGHSCORES",4,false,$lesson->highscores)); fwrite ($bf,full_tag("MAXHIGHSCORES",4,false,$lesson->maxhighscores)); fwrite ($bf,full_tag("AVAILABLE",4,false,$lesson->available)); fwrite ($bf,full_tag("DEADLINE",4,false,$lesson->deadline)); @@ -186,7 +186,7 @@ fwrite ($bf,full_tag("FLAGS",8,false,$answer->flags)); fwrite ($bf,full_tag("TIMECREATED",8,false,$answer->timecreated)); fwrite ($bf,full_tag("TIMEMODIFIED",8,false,$answer->timemodified)); - fwrite ($bf,full_tag("ANSWERTEXT",8,false,$answer->answer)); // THIS MIGHT BE WRONG, IT IS ANSWER IN DB MARKN + fwrite ($bf,full_tag("ANSWERTEXT",8,false,$answer->answer)); fwrite ($bf,full_tag("RESPONSE",8,false,$answer->response)); //Now we backup any lesson attempts (if student data required) if ($preferences->mods["lesson"]->userinfo) { @@ -212,22 +212,22 @@ //If there are attempts if ($lesson_attempts) { //Write start tag - $status =fwrite ($bf,start_tag("ATTEMPTS",4,true)); + $status =fwrite ($bf,start_tag("ATTEMPTS",8,true)); //Iterate over each attempt foreach ($lesson_attempts as $attempt) { //Start Attempt - $status =fwrite ($bf,start_tag("ATTEMPT",5,true)); + $status =fwrite ($bf,start_tag("ATTEMPT",9,true)); //Print attempt contents - fwrite ($bf,full_tag("USERID",6,false,$attempt->userid)); - fwrite ($bf,full_tag("RETRY",6,false,$attempt->retry)); - fwrite ($bf,full_tag("CORRECT",6,false,$attempt->correct)); - fwrite ($bf,full_tag("USERANSWER",6,false,$attempt->useranswer)); - fwrite ($bf,full_tag("TIMESEEN",6,false,$attempt->timeseen)); + fwrite ($bf,full_tag("USERID",10,false,$attempt->userid)); + fwrite ($bf,full_tag("RETRY",10,false,$attempt->retry)); + fwrite ($bf,full_tag("CORRECT",10,false,$attempt->correct)); + fwrite ($bf,full_tag("USERANSWER",10,false,$attempt->useranswer)); + fwrite ($bf,full_tag("TIMESEEN",10,false,$attempt->timeseen)); //End attempt - $status =fwrite ($bf,end_tag("ATTEMPT",5,true)); + $status =fwrite ($bf,end_tag("ATTEMPT",9,true)); } //Write end tag - $status =fwrite ($bf,end_tag("ATTEMPTS",4,true)); + $status =fwrite ($bf,end_tag("ATTEMPTS",8,true)); } return $status; } @@ -245,21 +245,21 @@ //If there is grades if ($grades) { //Write start tag - $status =fwrite ($bf,start_tag("GRADES",8,true)); + $status =fwrite ($bf,start_tag("GRADES",4,true)); //Iterate over each grade foreach ($grades as $grade) { //Start grade - $status =fwrite ($bf,start_tag("GRADE",9,true)); + $status =fwrite ($bf,start_tag("GRADE",5,true)); //Print grade contents - fwrite ($bf,full_tag("USERID",10,false,$grade->userid)); - fwrite ($bf,full_tag("GRADE_VALUE",10,false,$grade->grade)); - fwrite ($bf,full_tag("LATE",10,false,$grade->late)); - fwrite ($bf,full_tag("COMPLETED",10,false,$grade->completed)); - //End comment - $status =fwrite ($bf,end_tag("GRADE",9,true)); + fwrite ($bf,full_tag("USERID",6,false,$grade->userid)); + fwrite ($bf,full_tag("GRADE_VALUE",6,false,$grade->grade)); + fwrite ($bf,full_tag("LATE",6,false,$grade->late)); + fwrite ($bf,full_tag("COMPLETED",6,false,$grade->completed)); + //End grade + $status =fwrite ($bf,end_tag("GRADE",5,true)); } //Write end tag - $status =fwrite ($bf,end_tag("GRADES",8,true)); + $status =fwrite ($bf,end_tag("GRADES",4,true)); } return $status; } @@ -271,7 +271,7 @@ $status = true; - // get the answers in a set order, the id order + // get the branches in a set order, the id order $lesson_branch = get_records("lesson_branch", "pageid", $pageno, "id"); //If there is lesson_branch @@ -282,10 +282,8 @@ foreach ($lesson_branch as $branch) { //Start branch $status =fwrite ($bf,start_tag("BRANCH",7,true)); - //Print answer contents - fwrite ($bf,full_tag("LESSONID",8,false,$branch->lessonid)); + //Print branch contents fwrite ($bf,full_tag("USERID",8,false,$branch->userid)); - fwrite ($bf,full_tag("PAGEID",8,false,$branch->pageid)); fwrite ($bf,full_tag("RETRY",8,false,$branch->retry)); fwrite ($bf,full_tag("FLAG",8,false,$branch->flag)); fwrite ($bf,full_tag("TIMESEEN",8,false,$branch->timeseen)); @@ -310,21 +308,20 @@ //If there is times if ($times) { //Write start tag - $status =fwrite ($bf,start_tag("TIMES",8,true)); + $status =fwrite ($bf,start_tag("TIMES",4,true)); //Iterate over each time foreach ($times as $time) { //Start time - $status =fwrite ($bf,start_tag("TIME",9,true)); + $status =fwrite ($bf,start_tag("TIME",5,true)); //Print time contents - fwrite ($bf,full_tag("LESSONID",10,false,$time->lessonid)); - fwrite ($bf,full_tag("USERID",10,false,$time->userid)); - fwrite ($bf,full_tag("STARTTIME",10,false,$time->starttime)); - fwrite ($bf,full_tag("LESSONTIME",10,false,$time->lessontime)); - //End comment - $status =fwrite ($bf,end_tag("TIME",9,true)); + fwrite ($bf,full_tag("USERID",6,false,$time->userid)); + fwrite ($bf,full_tag("STARTTIME",6,false,$time->starttime)); + fwrite ($bf,full_tag("LESSONTIME",6,false,$time->lessontime)); + //End time + $status =fwrite ($bf,end_tag("TIME",5,true)); } //Write end tag - $status =fwrite ($bf,end_tag("TIMES",8,true)); + $status =fwrite ($bf,end_tag("TIMES",4,true)); } return $status; } @@ -340,21 +337,20 @@ //If there is highscores if ($highscores) { //Write start tag - $status =fwrite ($bf,start_tag("HIGHSCORES",8,true)); + $status =fwrite ($bf,start_tag("HIGHSCORES",4,true)); //Iterate over each highscore foreach ($highscores as $highscore) { //Start highscore - $status =fwrite ($bf,start_tag("HIGHSCORE",9,true)); + $status =fwrite ($bf,start_tag("HIGHSCORE",5,true)); //Print highscore contents - fwrite ($bf,full_tag("LESSONID",10,false,$highscore->lessonid)); - fwrite ($bf,full_tag("USERID",10,false,$highscore->userid)); - fwrite ($bf,full_tag("GRADEID",10,false,$highscore->gradeid)); - fwrite ($bf,full_tag("NICKNAME",10,false,$highscore->nickname)); - //End comment - $status =fwrite ($bf,end_tag("HIGHSCORE",9,true)); + fwrite ($bf,full_tag("USERID",6,false,$highscore->userid)); + fwrite ($bf,full_tag("GRADEID",6,false,$highscore->gradeid)); + fwrite ($bf,full_tag("NICKNAME",6,false,$highscore->nickname)); + //End highscore + $status =fwrite ($bf,end_tag("HIGHSCORE",5,true)); } //Write end tag - $status =fwrite ($bf,end_tag("HIGHSCORES",8,true)); + $status =fwrite ($bf,end_tag("HIGHSCORES",4,true)); } return $status; } @@ -369,8 +365,7 @@ $default = get_record("lesson_default", "course", $preferences->backup_course); if ($default) { //Start mod - $status =fwrite ($bf,start_tag("DEFAULTS",3,true)); - $status =fwrite ($bf,start_tag("DEFAULT",4,true)); + $status =fwrite ($bf,start_tag("DEFAULTS",4,true)); //Print default data fwrite ($bf,full_tag("PRACTICE",5,false,$default->practice)); fwrite ($bf,full_tag("MODATTEMPTS",5,false,$default->modattempts)); @@ -397,8 +392,7 @@ fwrite ($bf,full_tag("DISPLAYLEFT",5,false,$default->displayleft)); fwrite ($bf,full_tag("HIGHSCORES",5,false,$default->highscores)); fwrite ($bf,full_tag("MAXHIGHSCORES",5,false,$default->maxhighscores)); - $status =fwrite ($bf,end_tag("DEFAULT",4,true)); - $status =fwrite ($bf,end_tag("DEFAULTS",3,true)); + $status =fwrite ($bf,end_tag("DEFAULTS",4,true)); } return $status; } diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index 450cf74dd21..0382f1e6a69 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -77,7 +77,7 @@ $lesson->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']); $lesson->bgcolor = backup_todb($info['MOD']['#']['BGCOLOR']['0']['#']); $lesson->displayleft = backup_todb($info['MOD']['#']['DISPLAYLEFT']['0']['#']); - $lesson->highscores = backup_todb($info['MOD']['#']['HIGHSCORES']['0']['#']); + $lesson->highscores = backup_todb($info['MOD']['#']['SHOWHIGHSCORES']['0']['#']); $lesson->maxhighscores = backup_todb($info['MOD']['#']['MAXHIGHSCORES']['0']['#']); $lesson->available = backup_todb($info['MOD']['#']['AVAILABLE']['0']['#']); $lesson->deadline = backup_todb($info['MOD']['#']['DEADLINE']['0']['#']); @@ -113,9 +113,6 @@ // is, there will only be one. $status = lesson_default_restore_mods($info,$restore); } - /*if ($restore->mods['lesson']->userinfo) { - $status = lesson_grades_restore_mods($newid,$info,$restore); - }*/ } else { $status = false; } @@ -161,10 +158,7 @@ //The structure is equal to the db, so insert the lesson_pages $newid = insert_record ("lesson_pages",$page); - // save the new pageids (needed to fix the absolute jumps in the answers) - $newpageid[backup_todb($page_info['#']['PAGEID']['0']['#'])] = $newid; - - // fix the forwards link of the previous page + //Fix the forwards link of the previous page if ($prevpageid) { if (!set_field("lesson_pages", "nextpageid", $newid, "id", $prevpageid)) { error("Lesson restorelib: unable to update link"); @@ -187,8 +181,8 @@ //We have to restore the lesson_answers table now (a page level table) $status = lesson_answers_restore($lessonid,$newid,$page_info,$restore); - // need to update useranswer field (which has answer id's in it) - // for matching and multi-answer multi-choice questions + //Need to update useranswer field (which has answer id's in it) + //for matching and multi-answer multi-choice questions if ($restore->mods["lesson"]->userinfo) { // firs check to see if we even have to do this // if multi-answer multi-choice question or matching if (($page->qtype == 3 && $page->qoption) || @@ -202,7 +196,7 @@ // $useranswer is an old answer id, so needs to be updated $useranswer = explode(",", $attempt->useranswer); foreach ($useranswer as $oldanswerid) { - $backupdata = backup_getid($restore->backup_unique_code,"answers",$oldanswerid); + $backupdata = backup_getid($restore->backup_unique_code,"lesson_answers",$oldanswerid); $newuseranswer[] = $backupdata->new_id; } // get the useranswer in the right format @@ -226,15 +220,17 @@ } } - // we've restored all the pages and answers, we now need to fix the jumps in the - // answer records if they are absolute + //We've restored all the pages and answers, we now need to fix the jumps in the + //answer records if they are absolute if ($answers = get_records("lesson_answers", "lessonid", $lessonid)) { foreach ($answers as $answer) { if ($answer->jumpto > 0) { // change the absolute page id - if (!set_field("lesson_answers", "jumpto", $newpageid[$answer->jumpto], "id", - $answer->id)) { - error("Lesson restorelib: unable to reset jump"); + $page = backup_getid($restore->backup_unique_code,"lesson_pages",$answer->jumpto); + if ($page) { + if (!set_field("lesson_answers", "jumpto", $page->new_id, "id", $answer->id)) { + error("Lesson restorelib: unable to reset jump"); + } } } } @@ -261,10 +257,13 @@ //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug + //We'll need this later!! + $oldid = backup_todb($answer_info['#']['ID']['0']['#']); + //Now, build the lesson_answers record structure $answer->lessonid = $lessonid; $answer->pageid = $pageid; - // the absolute jumps will need fixing + // the absolute jumps will need fixing later $answer->jumpto = backup_todb($answer_info['#']['JUMPTO']['0']['#']); $answer->grade = backup_todb($answer_info['#']['GRADE']['0']['#']); $answer->score = backup_todb($answer_info['#']['SCORE']['0']['#']); @@ -289,9 +288,8 @@ if ($newid) { // need to store the id so we can update the useranswer // field in attempts. This is done in the lesson_pages_restore_mods - backup_putid($restore->backup_unique_code,"answers", - backup_todb($answer_info['#']['ID']['0']['#']), $newid); - + backup_putid($restore->backup_unique_code,"lesson_answers", $oldid, $newid); + if ($restore->mods['lesson']->userinfo) { //We have to restore the lesson_attempts table now (a answers level table) $status = lesson_attempts_restore($lessonid, $pageid, $newid, $answer_info, $restore); @@ -389,7 +387,7 @@ //We have to recode the userid field $user = backup_getid($restore->backup_unique_code,"user",$olduserid); if ($user) { - $attempt->userid = $user->new_id; + $grade->userid = $user->new_id; } //The structure is equal to the db, so insert the lesson_grade @@ -517,7 +515,8 @@ return $status; } - //This function restores the lesson_high_score + + //This function restores the lesson_high_scores function lesson_high_scores_restore_mods($lessonid, $info, $restore) { global $CFG; @@ -525,9 +524,9 @@ $status = true; //Get the highscores array (optional) - if (isset($info['#']['HIGHSCORES']['0']['#']['HIGHSCORE'])) { - $highscores = $info['#']['HIGHSCORES']['0']['#']['HIGHSCORE']; - //Iterate over times + if (isset($info['MOD']['#']['HIGHSCORES']['0']['#']['HIGHSCORE'])) { + $highscores = $info['MOD']['#']['HIGHSCORES']['0']['#']['HIGHSCORE']; + //Iterate over highscores for($i = 0; $i < sizeof($highscores); $i++) { $highscore_info = $highscores[$i]; //traverse_xmlize($highscore_info); //Debug @@ -537,7 +536,7 @@ //We'll need this later!! $olduserid = backup_todb($highscore_info['#']['USERID']['0']['#']); - //Now, build the lesson_time record structure + //Now, build the lesson_highscores record structure $highscore->lessonid = $lessonid; $highscore->userid = backup_todb($highscore_info['#']['USERID']['0']['#']); $highscore->gradeid = backup_todb($highscore_info['#']['GRADEID']['0']['#']); @@ -550,7 +549,7 @@ } //The structure is equal to the db, so insert the lesson_grade - $newid = insert_record ("lesson_high_score",$highscore); + $newid = insert_record ("lesson_high_scores",$highscore); //Do some output if (($i+1) % 50 == 0) { @@ -578,13 +577,13 @@ $status = true; //Get the default array (optional) - if (isset($info['MOD']['#']['DEFAULTS']['0']['#']['DEFAULT'])) { - $defaults = $info['MOD']['#']['DEFAULTS']['0']['#']['DEFAULT']; + if (isset($info['MOD']['#']['DEFAULTS'])) { + $defaults = $info['MOD']['#']['DEFAULTS']; //Iterate over defaults (should only be 1!) for($i = 0; $i < sizeof($defaults); $i++) { $default_info = $defaults[$i]; - //traverse_xmlize($defaults_info); //Debug + //traverse_xmlize($default_info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug