From: stronk7 Date: Mon, 22 Sep 2003 00:06:51 +0000 (+0000) Subject: Now glossary categories are inbackup/restore too !! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=86db7a137d632ceaa5f1e542c1b5fa55ae752761;p=moodle.git Now glossary categories are inbackup/restore too !! Not tested !! --- diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index d7c42f8ed4..39b7b55fd8 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -84,7 +84,9 @@ if ($entries) { $status =fwrite ($bf,start_tag("ENTRIES",6,true)); foreach ($entries as $entry) { - fwrite ($bf,full_tag("ENTRYID",7,false,$entry->entryid)); + fwrite ($bf,start_tag("ENTRY",7,true)); + fwrite ($bf,full_tag("ENTRYID",8,false,$entry->entryid)); + $status =fwrite ($bf,end_tag("ENTRY",7,true)); } $status =fwrite ($bf,end_tag("ENTRIES",6,true)); } diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index 4fa755fdff..c1309cb963 100644 --- a/mod/glossary/restorelib.php +++ b/mod/glossary/restorelib.php @@ -66,7 +66,7 @@ //Restore glossary_entries $status = glossary_entries_restore_mods($mod->id,$newid,$info,$restore); //Restore glossary_categories and glossary_category_entries -// $status = glossary_categories_restore_mods($mod->id,$newid,$info,$restore); + $status = glossary_categories_restore_mods($mod->id,$newid,$info,$restore); } else { $status = false; } @@ -148,7 +148,7 @@ return $status; } - //This function restores the glossary_categories and entries_categories + //This function restores the glossary_categories function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) { global $CFG; @@ -158,9 +158,12 @@ //Get the categories array $categories = $info['MOD']['#']['CATEGORIES']['0']['#']['CATEGORY']; - //Iterate over entries + //Iterate over categories for($i = 0; $i < sizeof($categories); $i++) { $cat_info = $categories[$i]; + //traverse_xmlize($cat_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug //We'll need this later!! $oldid = backup_todb($cat_info['#']['ID']['0']['#']); @@ -179,10 +182,12 @@ } backup_flush(300); } + if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code,"glossary_categories",$oldid,$newid); - //Now copy moddata associated files if needed + //Now restore glossary_entries_categories + $status = glossary_entries_categories_restore_mods($old,$newid,$cat_info,$restore); } else { $status = false; } @@ -191,6 +196,53 @@ return $status; } + + //This function restores the glossary_entries_categories + function glossary_entries_categories_restore_mods($old_category_id,$new_category_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the entryids array + $entryids = $info['#']['ENTRIES']['0']['#']['ENTRY']; + + //Iterate over entryids + for($i = 0; $i < sizeof($entryids); $i++) { + $ent_info = $entryids[$i]; + //traverse_xmlize($ent_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //Now, build the GLOSSARY_ENTRIES_CATEGORIES record structure + $entry_category->categoryid = $new_category_id; + $entry_category->entryid = backup_todb($ent_info['#']['ENTRYID']['0']['#']); + + //We have to recode the entryid field + $entry = backup_getid($restore->backup_unique_code,"glossary_entries",$entry_category->entryid); + if ($entry) { + $entry_category->entryid = $entry->new_id; + } + + $newid = insert_record ("glossary_entries_categories",$entry_category); + + //Do some output + if (($i+1) % 50 == 0) { + echo "."; + if (($i+1) % 1000 == 0) { + echo "
"; + } + backup_flush(300); + } + + if (!$newid) { + $status = false; + } + } + + return $status; + } + //This function copies the glossary related info from backup temp dir to course moddata folder, //creating it if needed and recoding everything (glossary id and entry id) function glossary_restore_files ($oldgloid, $newgloid, $oldentryid, $newentryid, $restore) {