From: stronk7 Date: Sun, 22 Feb 2004 19:11:09 +0000 (+0000) Subject: Now lesson logs are restored too!! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c6c8272ae799f446b845b8cefd26108acbc8c9cd;p=moodle.git Now lesson logs are restored too!! --- diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index b18f7e2879..adfd14493b 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -69,6 +69,8 @@ CREATE TABLE `prefix_lesson_grades` ( # -------------------------------------------------------- +INSERT INTO prefix_log_display VALUES ('lesson', 'add', 'lesson', 'name'); +INSERT INTO prefix_log_display VALUES ('lesson', 'update', 'lesson', 'name'); INSERT INTO prefix_log_display VALUES ('lesson', 'start', 'lesson', 'name'); INSERT INTO prefix_log_display VALUES ('lesson', 'end', 'lesson', 'name'); INSERT INTO prefix_log_display VALUES ('lesson', 'view', 'lesson_pages', 'title'); diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index 64e4ec7e10..9544ac1eb7 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -107,6 +107,8 @@ //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug + //We'll need this later!! + $oldid = backup_todb($page_info['#']['PAGEID']['0']['#']); //Now, build the lesson_pages record structure $page->lessonid = $lessonid; @@ -116,7 +118,7 @@ $page->title = backup_todb($page_info['#']['TITLE']['0']['#']); $page->contents = backup_todb($page_info['#']['CONTENTS']['0']['#']); - //The structure is equal to the db, so insert the lesson_elements + //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) @@ -140,6 +142,8 @@ } if ($newid) { + //We have the newid, update backup_ids (restore logs will use it!!) + backup_putid($restore->backup_unique_code,"lesson_pages", $oldid, $newid); //We have to restore the lesson_answers table now (a page level table) $status = lesson_answers_restore($lessonid,$newid,$page_info,$restore); } else { @@ -326,4 +330,81 @@ return $status; } + //This function returns a log record with all the necessay transformations + //done. It's used by restore_log_module() to restore modules log. + function lesson_restore_logs($restore,$log) { + + $status = false; + + //Depending of the action, we recode different things + switch ($log->action) { + case "add": + if ($log->cmid) { + //Get the new_id of the module (to recode the info field) + $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info); + if ($mod) { + $log->url = "view.php?id=".$log->cmid; + $log->info = $mod->new_id; + $status = true; + } + } + break; + case "update": + if ($log->cmid) { + //Get the new_id of the module (to recode the info field) + $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info); + if ($mod) { + $log->url = "view.php?id=".$log->cmid; + $log->info = $mod->new_id; + $status = true; + } + } + break; + case "view all": + $log->url = "index.php?id=".$log->course; + $status = true; + break; + case "start": + if ($log->cmid) { + //Get the new_id of the module (to recode the info field) + $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info); + if ($mod) { + $log->url = "view.php?id=".$log->cmid; + $log->info = $mod->new_id; + $status = true; + } + } + break; + case "end": + if ($log->cmid) { + //Get the new_id of the module (to recode the info field) + $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info); + if ($mod) { + $log->url = "view.php?id=".$log->cmid; + $log->info = $mod->new_id; + $status = true; + } + } + break; + case "view": + if ($log->cmid) { + //Get the new_id of the page (to recode the url field) + $pag = backup_getid($restore->backup_unique_code,"lesson_pages",$log->info); + if ($pag) { + $log->url = "view.php?id=".$log->cmid."&action=navigation&pageid=".$pag->new_id; + $log->info = $pag->new_id; + $status = true; + } + } + break; + default: + echo "action (".$log->module."-".$log->action.") unknow. Not restored
"; //Debug + break; + } + + if ($status) { + $status = $log; + } + return $status; + } ?>