From 93766dbd6a913794b0c3324f1f7e6a44b7ca569d Mon Sep 17 00:00:00 2001
From: stronk7 <stronk7>
Date: Wed, 18 Feb 2004 22:29:50 +0000
Subject: [PATCH] Now glossary logs are restored too !! :-)

---
 mod/glossary/restorelib.php | 186 +++++++++++++++++++++++++++++++++++-
 1 file changed, 184 insertions(+), 2 deletions(-)

diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php
index cff7b76fc3..adce929b3c 100644
--- a/mod/glossary/restorelib.php
+++ b/mod/glossary/restorelib.php
@@ -206,6 +206,9 @@
             //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']['#']);
@@ -230,8 +233,10 @@
                 }
                 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;
             }
         }
@@ -476,4 +481,181 @@
         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;
+    }
 ?>
-- 
2.39.5