]> git.mjollnir.org Git - moodle.git/commitdiff
Now lesson logs are restored too!!
authorstronk7 <stronk7>
Sun, 22 Feb 2004 19:11:09 +0000 (19:11 +0000)
committerstronk7 <stronk7>
Sun, 22 Feb 2004 19:11:09 +0000 (19:11 +0000)
mod/lesson/db/mysql.sql
mod/lesson/restorelib.php

index b18f7e2879570350a0ff3394c48d11b9cd6e19cc..adfd14493b9a41d9053e055be2480b6efd473729 100644 (file)
@@ -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');
index 64e4ec7e103c792ce2604a65e24496bc4f32d5fa..9544ac1eb77923da2a2833138822f7ffe0a1626b 100644 (file)
             //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;
             $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)
             }
 
             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 {
         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<br>";                 //Debug
+            break;
+        }
+
+        if ($status) {
+            $status = $log;
+        }
+        return $status;
+    }
 ?>