From 46ea6d74da53edc63963305e43969b05ad59d5ce Mon Sep 17 00:00:00 2001 From: stronk7 Date: Tue, 16 Sep 2003 21:45:50 +0000 Subject: [PATCH] Now entries attachments are in backup too. This module is slighty different because when "no user info" is selected, teacher entries are exported so, instead of copying all the moddata/glossary dir (as other modules), files are copied selectively !! --- mod/glossary/backuplib.php | 89 +++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index 937cd8174c..4c29f0a800 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -10,7 +10,7 @@ // | // | // glossary_entries - // (UL,pk->id, fk->glossaryid, files) + // (UL,pk->id, fk->glossaryid, files) // // Meaning: pk->primary key field of the table // fk->foreign key to link with parent @@ -56,7 +56,7 @@ return $status; } - //Backup glossary_entries contents made by teachers (executed from glossary_backup_mods) + //Backup glossary_entries contents (executed from glossary_backup_mods) function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) { global $CFG; @@ -66,44 +66,48 @@ $glossary_entries = get_records("glossary_entries","glossaryid",$glossary,"id"); //If there is submissions if ($glossary_entries) { - $dumped_entries = 0; + $dumped_entries = 0; - //Iterate over each answer + //Iterate over each entry foreach ($glossary_entries as $glo_ent) { - //Start answer - + //Start entry //Print submission contents - if ( $glo_ent->teacherentry or $userinfo) { - $dumped_entries++; - if ($dumped_entries == 1) { - //Write start tag - $status =fwrite ($bf,start_tag("ENTRIES",4,true)); - } - $status =fwrite ($bf,start_tag("ENTRY",5,true)); - - fwrite ($bf,full_tag("ID",6,false,$glo_ent->id)); - fwrite ($bf,full_tag("USERID",6,false,$glo_ent->userid)); - fwrite ($bf,full_tag("CONCEPT",6,false,$glo_ent->concept)); - fwrite ($bf,full_tag("DEFINITION",6,false,$glo_ent->definition)); - fwrite ($bf,full_tag("FORMAT",6,false,$glo_ent->format)); - fwrite ($bf,full_tag("ATTACHMENT",6,false,$glo_ent->attachment)); - fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry)); - - $status =fwrite ($bf,end_tag("ENTRY",5,true)); - } + if ($glo_ent->teacherentry or $userinfo) { + $dumped_entries++; + if ($dumped_entries == 1) { + //Write start tag + $status =fwrite ($bf,start_tag("ENTRIES",4,true)); + } + $status =fwrite ($bf,start_tag("ENTRY",5,true)); + + fwrite ($bf,full_tag("ID",6,false,$glo_ent->id)); + fwrite ($bf,full_tag("USERID",6,false,$glo_ent->userid)); + fwrite ($bf,full_tag("CONCEPT",6,false,$glo_ent->concept)); + fwrite ($bf,full_tag("DEFINITION",6,false,$glo_ent->definition)); + fwrite ($bf,full_tag("FORMAT",6,false,$glo_ent->format)); + fwrite ($bf,full_tag("ATTACHMENT",6,false,$glo_ent->attachment)); + fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry)); + + $status =fwrite ($bf,end_tag("ENTRY",5,true)); + + //Now include entry attachment in backup (if it exists) + if ($glo_ent->attachment) { + $status = backup_glossary_files($bf,$preferences,$glossary,$glo_ent->id); + } + } + } + if ( $dumped_entries > 0 ) { + //Write end tag + $status =fwrite ($bf,end_tag("ENTRIES",4,true)); } - if ( $dumped_entries > 0 ) { - //Write end tag - $status =fwrite ($bf,end_tag("ENTRIES",4,true)); - } } return $status; } //Backup glossary files because we've selected to backup user info - //and files are user info's level - function backup_glossary_files($bf,$preferences) { + //or current entry is a teacher entry + function backup_glossary_files($bf,$preferences,$glossary,$entry) { global $CFG; @@ -112,12 +116,27 @@ //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 forum dir + + //Now we check that moddata/glossary dir exists and create it as necessary + //in temp/backup/$backup_code/moddata dir + $glo_dir_to = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code. + "/".$CFG->moddata."/glossary"; + //Let's create it as necessary + $status = check_dir_exists($glo_dir_to,true); + + //Now we check that the moddata/glossary/$glossary dir exists and create it as necessary + //in temp/backup/$backup_code/moddata/glossary + $status = check_dir_exists($glo_dir_to."/".$glossary,true); + + //Now copy the moddata/glossary/$glossary/$entry to + //temp/backup/$backup_code/moddata/glossary/$glossary/$entry if ($status) { - //Only if it exists !! Thanks to Daniel Miksik. - if (is_dir($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/glossary")) { - $status = backup_copy_file($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/glossary", - $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/moddata/glossary"); + //Calculate moddata/glossary dir + $glo_dir_from = $CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/glossary"; + //Only if it exists !! + if (is_dir($glo_dir_from."/".$glossary."/".$entry)) { + $status = backup_copy_file($glo_dir_from."/".$glossary."/".$entry, + $glo_dir_to."/".$glossary."/".$entry); } } -- 2.39.5