From: stronk7 Date: Sun, 15 Feb 2004 00:54:56 +0000 (+0000) Subject: Now chat logs are included in restore. I've decided to start with this X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ea3591e41a3990cec668319d8d9163eecf8ae453;p=moodle.git Now chat logs are included in restore. I've decided to start with this simple module to be ready for the difficults... :-) --- diff --git a/backup/restorelib.php b/backup/restorelib.php index 2abbef6358..34d4bfb82e 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1154,6 +1154,8 @@ if ($cm) { //echo "Module ".$dblog->cmid." to module ".$cm->new_id."
"; //Debug $dblog->cmid = $cm->new_id; + } else { + $dblog->cmid = 0; } } //print_object ($dblog); //Debug @@ -1304,7 +1306,7 @@ $toinsert = true; break; default: - //echo "action (".$log->action.") unknow. Not restored
"; //Debug + echo "action (".$log->module."-".$log->action.") unknow. Not restored
"; //Debug break; } @@ -1375,7 +1377,30 @@ function restore_log_module($restore,$log) { $status = true; + $toinsert = false; + + //echo "
Before transformations
"; //Debug + //print_object($log); //Debug + + //Now we see if the required function in the module exists + $function = $log->module."_restore_logs"; + if (function_exists($function)) { + //Call the function + $log = $function($restore,$log); + //If everything is ok, mark the insert flag + if ($log) { + $toinsert = true; + } + } + //echo "After transformations
"; //Debug + //print_object($log); //Debug + + //Now if $toinsert is set, insert the record + if ($toinsert) { + //echo "Inserting record
"; //Debug + $status = insert_record("log",$log); + } return $status; } diff --git a/mod/chat/restorelib.php b/mod/chat/restorelib.php index e3306b96e4..85c3ff67e5 100644 --- a/mod/chat/restorelib.php +++ b/mod/chat/restorelib.php @@ -126,4 +126,60 @@ } 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 chat_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; + default: + echo "action (".$log->module."-".$log->action.") unknow. Not restored
"; //Debug + break; + } + + if ($status) { + $status = $log; + } + return $status; + } ?>