Now generate mod info about assignments (with file copy to temp/backup)

and resources.
This commit is contained in:
stronk7 2003-05-10 17:25:20 +00:00
parent 2f518143de
commit efead3b909
11 changed files with 268 additions and 31 deletions

View 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

View file

@ -159,17 +159,46 @@
}
//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);
}
}

View file

@ -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;
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
return $status;
}
?>

View file

@ -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

View 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)) {

View 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)) {

View 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)) {

View 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";
}

View 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)

View file

@ -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)

View 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)) {