From: stronk7 Date: Sat, 10 May 2003 17:25:20 +0000 (+0000) Subject: Now generate mod info about assignments (with file copy to temp/backup) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=efead3b909e968277db3e84522f1a969922fdcc9;p=moodle.git Now generate mod info about assignments (with file copy to temp/backup) and resources. --- diff --git a/backup/STATUS.txt b/backup/STATUS.txt index 4e505c0d20..ca9127074d 100644 --- a/backup/STATUS.txt +++ b/backup/STATUS.txt @@ -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 diff --git a/backup/backup_execute.html b/backup/backup_execute.html index 4480547e06..7674ce5791 100644 --- a/backup/backup_execute.html +++ b/backup/backup_execute.html @@ -159,17 +159,46 @@ } //Print logs if selected - if ($preferences->backup_logs) { - echo "
  • Writing logs info"; - //User info - if ($status) { + if ($status) { + if ($preferences->backup_logs) { + echo "
  • 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 "
  • Writing modules info"; + //Start modules tag + $status = backup_modules_start ($backup_file,$preferences); + //Open ul for module list + echo ""; + //Close modules tag + $status = backup_modules_end ($backup_file,$preferences); + } + } + + + diff --git a/backup/lib.php b/backup/lib.php index 1744f61fe7..3076aaa160 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -287,6 +287,19 @@ 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) { @@ -780,7 +793,7 @@ $status = true; - $logs = get_records ("log","course",$preferences->backup_course); + $logs = get_records ("log","course",$preferences->backup_course,"time"); //We have logs if ($logs) { @@ -790,11 +803,12 @@ 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)); @@ -804,15 +818,90 @@ 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 + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + + ?> diff --git a/backup/mod/assignment/backuplib.php b/backup/mod/assignment/backuplib.php index 0412a76854..5bbbaae973 100644 --- a/backup/mod/assignment/backuplib.php +++ b/backup/mod/assignment/backuplib.php @@ -21,10 +21,104 @@ // //----------------------------------------------------------- - 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 diff --git a/backup/mod/choice/backuplib.php b/backup/mod/choice/backuplib.php index 3fdf518bfa..fbb32f2e02 100644 --- a/backup/mod/choice/backuplib.php +++ b/backup/mod/choice/backuplib.php @@ -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)) { diff --git a/backup/mod/forum/backuplib.php b/backup/mod/forum/backuplib.php index 33a4b86cd3..63ac38e304 100644 --- a/backup/mod/forum/backuplib.php +++ b/backup/mod/forum/backuplib.php @@ -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)) { diff --git a/backup/mod/journal/backuplib.php b/backup/mod/journal/backuplib.php index 519a601b57..55f172099f 100644 --- a/backup/mod/journal/backuplib.php +++ b/backup/mod/journal/backuplib.php @@ -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)) { diff --git a/backup/mod/pgassignment/backuplib.php b/backup/mod/pgassignment/backuplib.php index fbe2a90810..25b68cb825 100644 --- a/backup/mod/pgassignment/backuplib.php +++ b/backup/mod/pgassignment/backuplib.php @@ -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"; } diff --git a/backup/mod/quiz/backuplib.php b/backup/mod/quiz/backuplib.php index 405083b35d..c849978826 100644 --- a/backup/mod/quiz/backuplib.php +++ b/backup/mod/quiz/backuplib.php @@ -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) diff --git a/backup/mod/resource/backuplib.php b/backup/mod/resource/backuplib.php index 4915763c6b..61e63b5a18 100644 --- a/backup/mod/resource/backuplib.php +++ b/backup/mod/resource/backuplib.php @@ -16,8 +16,32 @@ // //----------------------------------------------------------- - 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) diff --git a/backup/mod/survey/backuplib.php b/backup/mod/survey/backuplib.php index e1b3533895..9f39f3a6da 100644 --- a/backup/mod/survey/backuplib.php +++ b/backup/mod/survey/backuplib.php @@ -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)) {