]> git.mjollnir.org Git - moodle.git/commitdiff
Now chat logs are included in restore. I've decided to start with this
authorstronk7 <stronk7>
Sun, 15 Feb 2004 00:54:56 +0000 (00:54 +0000)
committerstronk7 <stronk7>
Sun, 15 Feb 2004 00:54:56 +0000 (00:54 +0000)
simple module to be ready for the difficults... :-)

backup/restorelib.php
mod/chat/restorelib.php

index 2abbef63581f1af3356b500b398a84af8456a4e8..34d4bfb82ed717b0ef194bda572b8f7c79605379 100644 (file)
                                 if ($cm) {
                                     //echo "Module ".$dblog->cmid." to module ".$cm->new_id."<br>";                         //Debug
                                     $dblog->cmid = $cm->new_id;
+                                } else {
+                                    $dblog->cmid = 0;
                                 }
                             }
                             //print_object ($dblog);                                                                        //Debug
             $toinsert = true;
             break;
         default:
-            //echo "action (".$log->action.") unknow. Not restored<br>";                 //Debug
+            echo "action (".$log->module."-".$log->action.") unknow. Not restored<br>";                 //Debug
             break;
         }
 
     function restore_log_module($restore,$log) {
 
         $status = true;
+        $toinsert = false;
+
+        //echo "<hr>Before transformations<br>";                                        //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<br>";                                             //Debug
+        //print_object($log);                                                           //Debug
+
+        //Now if $toinsert is set, insert the record
+        if ($toinsert) {
+            //echo "Inserting record<br>";                                              //Debug
+            $status = insert_record("log",$log);
+        }
         return $status;
     }
 
index e3306b96e47ffc503500a71a56d8d24dd3bbf7e2..85c3ff67e5db8198bc247eaa503b61ec0b507e92 100644 (file)
         }
         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<br>";                 //Debug
+            break;
+        }
+
+        if ($status) {
+            $status = $log;
+        }
+        return $status;
+    }
 ?>