]> git.mjollnir.org Git - moodle.git/commitdiff
Now glossary logs are restored too !! :-)
authorstronk7 <stronk7>
Wed, 18 Feb 2004 22:29:50 +0000 (22:29 +0000)
committerstronk7 <stronk7>
Wed, 18 Feb 2004 22:29:50 +0000 (22:29 +0000)
mod/glossary/restorelib.php

index cff7b76fc39c1fec706ef08c53ea0fb14ef7097d..adce929b3c8d5fe7e371488847255e681c6430c6 100644 (file)
             //print_object ($GLOBALS['traverse_array']);                                                  //Debug
             //$GLOBALS['traverse_array']="";                                                              //Debug
 
+            //We'll need this later!!
+            $oldid = backup_todb($com_info['#']['ID']['0']['#']);
+
             //Now, build the GLOSSARY_COMMENTS record structure
             $comment->entryid = $new_entry_id;
             $comment->userid = backup_todb($com_info['#']['USERID']['0']['#']);
                 }
                 backup_flush(300);
             }
-
-            if (!$newid) {
+            if ($newid) { 
+                //We have the newid, update backup_ids
+                backup_putid($restore->backup_unique_code,"glossary_comments",$oldid,$newid);
+            } else {
                 $status = false;
             }
         }
         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 glossary_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":
+            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 "add category":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_category (to recode the info field)
+                $cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
+                if ($cat) {
+                    $log->url = "editcategories.php?id=".$log->cmid;
+                    $log->info = $cat->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "edit category":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_category (to recode the info field)
+                $cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
+                if ($cat) {
+                    $log->url = "editcategories.php?id=".$log->cmid;
+                    $log->info = $cat->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "delete category":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_category (to recode the info field)
+                $cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
+                if ($cat) {
+                    $log->url = "editcategories.php?id=".$log->cmid;
+                    $log->info = $cat->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "add entry":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_entry (to recode the info and url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
+                if ($ent) {
+                    $log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
+                    $log->info = $ent->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "update entry":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_entry (to recode the info and url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
+                if ($ent) {
+                    $log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
+                    $log->info = $ent->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "delete entry":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_entry (to recode the info and url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
+                if ($ent) {
+                    $log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
+                    $log->info = $ent->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "approve entry":
+            if ($log->cmid) {
+                //Get the new_id of the glossary_entry (to recode the info and url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
+                if ($ent) {
+                    $log->url = "showentry.php?id=".$log->cmid."&eid=".$ent->new_id;
+                    $log->info = $ent->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "add comment":
+            if ($log->cmid) {
+                //Extract the entryid from the url field
+                $entid = substr(strrchr($log->url,"="),1);
+                //Get the new_id of the glossary_entry (to recode the url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
+                //Get the new_id of the glossary_comment (to recode the info field)
+                $com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
+                if ($ent and $com) {
+                    $log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
+                    $log->info = $com->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "update comment":
+            if ($log->cmid) {
+                //Extract the entryid from the url field
+                $entid = substr(strrchr($log->url,"="),1);
+                //Get the new_id of the glossary_entry (to recode the url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
+                //Get the new_id of the glossary_comment (to recode the info field)
+                $com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
+                if ($ent and $com) {
+                    $log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
+                    $log->info = $com->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        case "delete comment":
+            if ($log->cmid) {
+                //Extract the entryid from the url field
+                $entid = substr(strrchr($log->url,"="),1);
+                //Get the new_id of the glossary_entry (to recode the url field)
+                $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
+                //Get the new_id of the glossary_comment (to recode the info field)
+                $com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
+                if ($ent and $com) {
+                    $log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
+                    $log->info = $com->new_id;
+                    $status = true;
+                }
+            }
+            break;
+        default:
+            echo "action (".$log->module."-".$log->action.") unknow. Not restored<br>";                 //Debug
+            break;
+        }
+
+        if ($status) {
+            $status = $log;
+        }
+        return $status;
+    }
 ?>