]> git.mjollnir.org Git - moodle.git/commitdiff
Now generate mod info about assignments (with file copy to temp/backup)
authorstronk7 <stronk7>
Sat, 10 May 2003 17:25:20 +0000 (17:25 +0000)
committerstronk7 <stronk7>
Sat, 10 May 2003 17:25:20 +0000 (17:25 +0000)
and resources.

backup/STATUS.txt
backup/backup_execute.html
backup/lib.php
backup/mod/assignment/backuplib.php
backup/mod/choice/backuplib.php
backup/mod/forum/backuplib.php
backup/mod/journal/backuplib.php
backup/mod/pgassignment/backuplib.php
backup/mod/quiz/backuplib.php
backup/mod/resource/backuplib.php
backup/mod/survey/backuplib.php

index 4e505c0d20c03a73528bc906a74f18e22ffb0e7f..ca9127074dd001c21cbc39c5a0b7c4cc0ad0ff6b 100644 (file)
@@ -49,10 +49,10 @@ Backup Details:
                  - All..........................................DONE 
            - Logs...............................................DONE
            - Mods Info..........................................IN PROGRESS
-              x assignments.....................................IN PROGRESS
-                 + course data..................................NO EXISTS
-                 + user data....................................NO EXISTS
-                 + files........................................NO EXISTS
+              x assignments.....................................DONE
+                 + course data..................................DONE
+                 + user data....................................DONE
+                 + files........................................DONE
               x choices.........................................IN PROGRESS
                  + course data..................................NO EXISTS
                  + user data....................................NO EXISTS
@@ -73,11 +73,12 @@ Backup Details:
                  + course data..................................NO EXISTS
                  + user data....................................NO EXISTS
                  + files........................................NO EXISTS
-              x resources.......................................IN PROGRESS
-                 + course data..................................NO EXISTS
-                 + user data....................................NO EXISTS
-                 + files........................................NO EXISTS
+              x resources.......................................DONE
+                 + course data..................................DONE
+                 + user data....................................DONE
+                 + files........................................ARE COURSE FILES !!
               x surveys.........................................IN PROGRESS
+              x workshops.......................................NO EXISTS
                  + course data..................................NO EXISTS
                  + user data....................................NO EXISTS
                  + files........................................NO EXISTS
index 4480547e067a4bca54d2dcf9915e593a8cd0d3a1..7674ce579147c8bf647c673fc6aae0f86a237cdd 100644 (file)
         }
         
         //Print logs if selected
-        if ($preferences->backup_logs) {  
-            echo "<li>Writing logs info";
-            //User info
-            if ($status) {
+        if ($status) {
+            if ($preferences->backup_logs) {  
+                echo "<li>Writing logs info";
                 $status = backup_log_info($backup_file,$preferences);
             }
         }
 
-        //Module info
-
-
+        //Module info, this unique function makes all the work!!
+        //db export and module fileis copy
+        if ($status) {
+            $mods_to_backup = false;
+            //Check if we have any mod to backup
+            foreach ($preferences->mods as $module) {
+                if ($module->backup) { 
+                    $mods_to_backup = true;
+                }    
+            }
+            //If we have to backup some module
+            if ($mods_to_backup) {
+                echo "<li>Writing modules info";
+                //Start modules tag
+                $status = backup_modules_start ($backup_file,$preferences);
+                //Open ul for module list
+                echo "<ul>";
+                //Iterate over modules and call backupa
+                foreach ($preferences->mods as $module) {
+                    if ($module->backup and $status) {
+                        echo "<li>".$module->name;
+                        $status = backup_module($backup_file,$preferences,$module->name);
+                    }
+                }
+                //Close ul for module list
+                echo "</ul>";
+                //Close modules tag
+                $status = backup_modules_end ($backup_file,$preferences);
+            }
+        }
+        
+        
+        
 
 
 
index 1744f61fe7cae4272cd5c9fd0055880af3953d2a..3076aaa1605fec2dfadfe51d90c5068054bf6032 100644 (file)
         return $status;
     }
 
+    //Function to check and create the needed moddata dir to
+    //save all the mod backup files. We always name it moddata
+    //to be able to restore it, but in restore we check for
+    //$CFG->moddata !!
+    function check_and_create_moddata_dir($backup_unique_code) {
+  
+        global $CFG;
+
+            $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/moddata",true);
+
+        return $status;
+    }
+
     //Function to delete all the directory contents recursively
     //Copied from admin/delete.php
     function delete_dir_contents ($rootdir) {
   
         $status = true;
 
-        $logs = get_records ("log","course",$preferences->backup_course);
+        $logs = get_records ("log","course",$preferences->backup_course,"time");
 
         //We have logs
         if ($logs) {
             foreach ($logs as $log) {
                 //See if it is a valid module to backup
                 if ($log->module == "course" or 
-                    $log->module == "user") {
+                    $log->module == "user" or
+                    $preferences->mods[$log->module]->backup == 1) {
                     //Begin log tag
                      fwrite ($bf,start_tag("LOG",3,true));
 
-                    //Output log data
+                    //Output log tag
                     fwrite ($bf,full_tag("ID",4,false,$log->id));
                     fwrite ($bf,full_tag("TIME",4,false,$log->time));
                     fwrite ($bf,full_tag("USERID",4,false,$log->userid));
                     fwrite ($bf,full_tag("URL",4,false,$log->url));
                     fwrite ($bf,full_tag("INFO",4,false,$log->info));
 
-                    //End log data
+                    //End log tag
                      fwrite ($bf,end_tag("LOG",3,true));
                 }
             }
+            //End logs tag
             $status = fwrite ($bf,end_tag("LOGS",2,true));
         }
+        return $status;
+    }
 
+    //Start the modules tag
+    function backup_modules_start ($bf,$preferences) {
+      
+        return fwrite ($bf,start_tag("MODULES",2,true));
+    }
+
+    //End the modules tag
+    function backup_modules_end ($bf,$preferences) {
+
+        return fwrite ($bf,end_tag("MODULES",2,true));
+    }
+
+    //This function makes all the necesary calls to every mod
+    //to export itself and its files !!!
+    function backup_module($bf,$preferences,$module) {
+         
+        global $CFG;
+
+        $status = true;
+
+        //First, re-check if necessary functions exists
+        $modbackup = $module."_backup_mods";
+        if (function_exists($modbackup)) {
+            //Call the function
+            $status = $modbackup($bf,$preferences);
+        } else {
+            //Something was wrong. Function should exist.
+            $status = false;
+        }
+   
+        return $status; 
         
+    }
 
-        return $status;
+    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    //This functions are used to copy any file or directory ($from_file)
+    //to a new file or directory ($to_file). It works recursively and
+    //mantains file perms.
+    //I've copied it from: http://www.php.net/manual/en/function.copy.php
+    //Little modifications done
+  
+    function backup_copy_file ($from_file,$to_file) {
+        if (is_file($from_file)) {
+            $perms=fileperms($from_file);
+            return copy($from_file,$to_file) && chmod($to_file,$perms);
+        }
+        else if (is_dir($from_file)) {
+            return backup_copy_dir($from_file,$to_file);
+        }
+        else{
+            return false;
+        }
     }
+
+    function backup_copy_dir($from_file,$to_file) {
+        if (!is_dir($to_file)) {
+            mkdir($to_file);
+            chmod("$to_file",0777);
+        }
+        $dir = opendir($from_file);
+        while ($file=readdir($dir)) {
+            if ($file=="." || $file=="..") {
+                continue;
+            }
+            return backup_copy_file ("$from_file/$file","$to_file/$file");
+        }
+        return closedir($dir);
+    }
+    ///Ends copy file/dirs functions
+    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+        
+
+
 ?>
index 0412a76854d7588971267878f0490556b05722cf..5bbbaae973385be097e1252e77bf4543be30b7e6 100644 (file)
     //
     //-----------------------------------------------------------
 
-    function assignment_backup_mods($course,$user_data=false,$backup_unique_code) {
-        print "hola";
+    //This function executes all the backup procedure about this mod
+    function assignment_backup_mods($bf,$preferences) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Iterate over assignment table
+        $assignments = get_records ("assignment","course",$preferences->backup_course,"id");
+        if ($assignments) {
+            foreach ($assignments as $assignment) {
+                //Start mod
+                fwrite ($bf,start_tag("MOD",3,true));
+                //Print assignment data
+                fwrite ($bf,full_tag("ID",4,false,$assignment->id));
+                fwrite ($bf,full_tag("MODTYPE",4,false,"assignment"));
+                fwrite ($bf,full_tag("NAME",4,false,$assignment->name));
+                fwrite ($bf,full_tag("DESCRIPTION",4,false,$assignment->description));
+                fwrite ($bf,full_tag("FORMAT",4,false,$assignment->format));
+                fwrite ($bf,full_tag("RESUBMIT",4,false,$assignment->resubmit));
+                fwrite ($bf,full_tag("TYPE",4,false,$assignment->type));
+                fwrite ($bf,full_tag("MAXBYTES",4,false,$assignment->maxbytes));
+                fwrite ($bf,full_tag("TIMEDUE",4,false,$assignment->timedue));
+                fwrite ($bf,full_tag("GRADE",4,false,$assignment->grade));
+                fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$assignment->timemodified));
+                //if we've selected to backup users info, then execute backup_assignment_submisions
+                if ($preferences->mods["assignment"]->userinfo) {
+                    $status = backup_assignment_submissions($bf,$preferences,$assignment->id);
+                }
+                //End mod
+                $status =fwrite ($bf,end_tag("MOD",3,true));
+            }
+        }
+        //if we've selected to backup users info, then backup files too
+        if ($preferences->mods["assignment"]->userinfo) {
+            $status = backup_assignment_files($bf,$preferences);
+        }
+        return $status;  
     }
 
+    //Backup assignment_submissions contents (executed from backup_assignment)
+    function backup_assignment_submissions ($bf,$preferences,$assignment) {
+
+        global $CFG;
+
+        $status = true;
+
+        $assignment_submissions = get_records("assignment_submissions","assignment",$assignment,"id");
+        //If there is submissions
+        if ($assignment_submissions) {
+            //Write start tag
+            $status =fwrite ($bf,start_tag("SUBMISSIONS",4,true));
+            //Iterate over each submission
+            foreach ($assignment_submissions as $ass_sub) {
+                //Start submission
+                $status =fwrite ($bf,start_tag("SUBMISSION",5,true));
+                //Print submission contents
+                fwrite ($bf,full_tag("ID",6,false,$ass_sub->id));       
+                fwrite ($bf,full_tag("USERID",6,false,$ass_sub->userid));       
+                fwrite ($bf,full_tag("TIMECREATED",6,false,$ass_sub->timecreated));       
+                fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$ass_sub->timemodified));       
+                fwrite ($bf,full_tag("NUMFILES",6,false,$ass_sub->numfiles));       
+                fwrite ($bf,full_tag("GRADE",6,false,$ass_sub->grade));       
+                fwrite ($bf,full_tag("COMMENT",6,false,$ass_sub->comment));       
+                fwrite ($bf,full_tag("TEACHER",6,false,$ass_sub->teacher));       
+                fwrite ($bf,full_tag("TIMEMARKED",6,false,$ass_sub->timemarked));       
+                fwrite ($bf,full_tag("MAILED",6,false,$ass_sub->mailed));       
+                //End submission
+                $status =fwrite ($bf,start_tag("SUBMISSION",5,true));
+            }
+            //Write end tag
+            $status =fwrite ($bf,end_tag("SUBMISSIONS",4,true));
+        }
+
+        return $status;
+    }
+
+    //Backup assignment files because we've selected to backup user info
+    //and files are user info's level
+    function backup_assignment_files($bf,$preferences) {
+
+        global $CFG;
+       
+        $status = true;
+
+        //First we check to moddata exists and create it as necessary
+        //in temp/backup/$backup_code  dir
+        $status = check_and_create_moddata_dir($preferences->backup_unique_code);
+        //Now copy the assignment dir
+        if ($status) {
+            $status = backup_copy_file($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/assignment",
+                                       $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/moddata/assignment");
+        }
+
+        return $status;
+
+    } 
+
     //Return an array of info (name,value)
     function assignment_check_backup_mods($course,$user_data=false,$backup_unique_code) {
         //First the course data
index 3fdf518bfaf9b323b0ae59c8c9dc1e5b395386b7..fbb32f2e021d860c13454b15f82144f5cc8eeb23 100644 (file)
@@ -26,7 +26,7 @@
     }
    
    ////Return an array of info (name,value)
-   function choice_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+   function NO_choice_check_backup_mods($course,$user_data=false,$backup_unique_code) {
         //First the course data
         $info[0][0] = get_string("modulenameplural","choice");
         if ($ids = choice_ids ($course)) {
index 33a4b86cd307dca6f441409944976ff02ad9d88c..63ac38e304e491f56e01d58bb9a64e0f67675ba6 100644 (file)
@@ -36,7 +36,7 @@
     }
 
    ////Return an array of info (name,value)
-   function forum_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+   function NO_forum_check_backup_mods($course,$user_data=false,$backup_unique_code) {
         //First the course data
         $info[0][0] = get_string("modulenameplural","forum");
         if ($ids = forum_ids ($course)) {
index 519a601b576702c1f11e0b6a9a631b8d69697292..55f172099f5adc0e97163443cd93ace19e651e9f 100644 (file)
@@ -26,7 +26,7 @@
     }
    
    ////Return an array of info (name,value)
-   function journal_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+   function NO_journal_check_backup_mods($course,$user_data=false,$backup_unique_code) {
         //First the course data
         $info[0][0] = get_string("modulenameplural","journal");
         if ($ids = journal_ids ($course)) {
index fbe2a908101a03bff1918931e03fb33227f03c26..25b68cb825683acbb5244382df4a8abfc2031132 100644 (file)
@@ -26,7 +26,7 @@
     //
     //-----------------------------------------------------------
 
-    function pgassignment_backup_mods($course,$user_data=false,$backup_unique_code) {
+    function NO_pgassignment_backup_mods($course,$user_data=false,$backup_unique_code) {
         print "hola";
     }
 
index 405083b35dfcd2b517fd13f1cc76db1bd2ddaf6f..c8499788262a1956b7ff5dbfe152268cf0d4bada 100644 (file)
@@ -55,7 +55,7 @@
     }
 
    ////Return an array of info (name,value)
-   function quiz_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+   function NO_quiz_check_backup_mods($course,$user_data=false,$backup_unique_code) {
         //Deletes data from mdl_backup_ids (categories section)
         delete_category_ids ($backup_unique_code);
         //Create date into mdl_backup_ids (categories section)
index 4915763c6beb74f71b9079d0fc347a2ca687cb5f..61e63b5a18bb81e6e8d3d6cf48b997de82df00b0 100644 (file)
     //
     //-----------------------------------------------------------
 
-    function resource_backup_mods($course,$user_data=false,$backup_unique_code) {
-        print "hola";
+    //This function executes all the backup procedure about this mod
+    function resource_backup_mods($bf,$preferences) {
+        global $CFG;
+
+        $status = true; 
+
+        ////Iterate over resource table
+        $resources = get_records ("resource","course",$preferences->backup_course,"id");
+        if ($resources) {
+            foreach ($resources as $resource) {
+                //Start mod
+                fwrite ($bf,start_tag("MOD",3,true));
+                //Print assignment data
+                fwrite ($bf,full_tag("ID",4,false,$resource->id));
+                fwrite ($bf,full_tag("MODTYPE",4,false,"resource"));
+                fwrite ($bf,full_tag("NAME",4,false,$resource->name));
+                fwrite ($bf,full_tag("TYPE",4,false,$resource->type));
+                fwrite ($bf,full_tag("REFERENCE",4,false,$resource->reference));
+                fwrite ($bf,full_tag("SUMMARY",4,false,$resource->summary));
+                fwrite ($bf,full_tag("ALLTEXT",4,false,$resource->alltext));
+                fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$resource->timemodified));
+                //End mod
+                $status = fwrite ($bf,end_tag("MOD",3,true));
+            }
+        }
+        return $status;
     }
    
    ////Return an array of info (name,value)
index e1b35338954b93b3691db4debe2bcaed0e9929b0..9f39f3a6dab09f08a06f4c7377fa3391e7694021 100644 (file)
@@ -27,7 +27,7 @@
     }
 
    ////Return an array of info (name,value)
-   function survey_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+   function NO_survey_check_backup_mods($course,$user_data=false,$backup_unique_code) {
         //First the course data
         $info[0][0] = get_string("modulenameplural","survey");
         if ($ids = survey_ids ($course)) {