From: stronk7 Date: Wed, 18 Feb 2004 22:29:50 +0000 (+0000) Subject: Now glossary logs are restored too !! :-) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=93766dbd6a913794b0c3324f1f7e6a44b7ca569d;p=moodle.git Now glossary logs are restored too !! :-) --- 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
"; //Debug + break; + } + + if ($status) { + $status = $log; + } + return $status; + } ?>