From 7965be79e3d7418e3f6f69a5466811685d4f8c16 Mon Sep 17 00:00:00 2001 From: willcast Date: Fri, 7 Nov 2003 15:58:29 +0000 Subject: [PATCH] - Backup/restore and Import/export aliases. --- mod/glossary/backuplib.php | 36 ++++++++++++++++++++----- mod/glossary/import.php | 12 +++++++++ mod/glossary/lib.php | 9 +++++++ mod/glossary/restorelib.php | 52 ++++++++++++++++++++++++++++++++----- 4 files changed, 97 insertions(+), 12 deletions(-) diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index 03ce86b6b5..834c9cc719 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -10,12 +10,12 @@ // | | // | | // glossary_entries -------------- glossary_entries_categories - // (UL,pk->id, fk->glossaryid, files) (UL, [pk->categoryid,entryid] - // | - // | - // | - // glossary_comments - // (UL,pk->id, fk->entryid) + // (UL,pk->id, fk->glossaryid, files) (UL, pk->categoryid,entryid] + // | \ + // | \ + // | \ + // glossary_comments --------- glossary_alias + // (UL,pk->id, fk->entryid) (UL, pk->id, pk->entryid) // // // Meaning: pk->primary key field of the table @@ -161,6 +161,8 @@ fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$glo_ent->timemodified)); fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry)); + $status = backup_glossary_aliases ($bf,$preferences,$glo_ent->id); + if ( $userinfo ) { $status = backup_glossary_comments ($bf,$preferences,$glo_ent->id); } @@ -207,6 +209,28 @@ return $status; } + //Backup glossary_alias contents (executed from backup_glossary_entries) + function backup_glossary_aliases ($bf,$preferences,$entryid) { + + global $CFG; + + $status = true; + + $aliases = get_records("glossary_alias","entryid",$entryid); + if ($aliases) { + $status =fwrite ($bf,start_tag("ALIASES",6,true)); + foreach ($aliases as $alias) { + $status =fwrite ($bf,start_tag("ALIAS",7,true)); + + fwrite ($bf,full_tag("NAME",8,false,$comment->id)); + + $status =fwrite ($bf,end_tag("ALIAS",7,true)); + } + $status =fwrite ($bf,end_tag("ALIASES",6,true)); + } + return $status; + } + //Backup glossary files because we've selected to backup user info //or current entry is a teacher entry function backup_glossary_files($bf,$preferences,$glossary,$entry) { diff --git a/mod/glossary/import.php b/mod/glossary/import.php index a78f951cf6..194520e172 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -199,6 +199,18 @@ if ( $newentry->id = insert_record("glossary_entries",$newentry) ) { $importedentries++; + + $xmlaliases = $xmlentry['#']['ALIASES'][0]['#']['ALIAS']; + for($k = 0; $k < sizeof($xmlaliases); $k++) { + /// Importing aliases + $xmlalias = $xmlaliases[$k]; + unset($newalias); + + $newalias->entryid = $newentry->id; + $newalias->alias = $xmlalias['#']['NAME'][0]['#']; + $newalias->id = insert_record("glossary_alias",$newalias)); + } + if ( $catsincl ) { // If the categories must be imported... $xmlcats = $xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 18f8270975..ac6c2d37de 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -1191,6 +1191,15 @@ global $CFG; fwrite($h,glossary_full_tag("FULLMATCH",4,false,$entry->fullmatch)); fwrite($h,glossary_full_tag("TEACHERENTRY",4,false,$entry->teacherentry)); + if ( $aliases = get_records("glossary_alias","entryid",$entry->id) ) { + $status = fwrite ($h,glossary_start_tag("ALIASES",4,true)); + foreach ($aliases as $alias) { + $status = fwrite ($h,glossary_start_tag("ALIAS",5,true)); + fwrite($h,glossary_full_tag("NAME",6,false,$alias->alias)); + $status = fwrite($h,glossary_end_tag("ALIAS",5,true)); + } + $status = fwrite($h,glossary_end_tag("CATEGORIES",4,true)); + } if ( $catentries = get_records("glossary_entries_categories","entryid",$entry->id) ) { $status = fwrite ($h,glossary_start_tag("CATEGORIES",4,true)); foreach ($catentries as $catentry) { diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index 7d495a3efe..c40d652685 100644 --- a/mod/glossary/restorelib.php +++ b/mod/glossary/restorelib.php @@ -11,11 +11,11 @@ // | | // glossary_entries -------------- glossary_entries_categories // (UL,pk->id, fk->glossaryid, files) (UL, [pk->categoryid,entryid] - // | - // | - // | - // glossary_comments - // (UL,pk->id, fk->entryid) + // | \ + // | \ + // | \ + // glossary_comments ------ glossary_alias + // (UL,pk->id, fk->entryid) (UL, pk->id, pk->entryid) // // // Meaning: pk->primary key field of the table @@ -153,7 +153,9 @@ } if ($newid) { //We have the newid, update backup_ids - backup_putid($restore->backup_unique_code,"glossary_entries",$oldid,$newid); + backup_putid($restore->backup_unique_code,"glossary_entries",$oldid,$newid); + //Restore glossary_alias + $status = glossary_alias_restore_mods($oldid,$newid,$ent_info,$restore); //Now restore glossary_comments $status = glossary_comments_restore_mods($oldid,$newid,$ent_info,$restore); //Now copy moddata associated files if needed @@ -220,6 +222,44 @@ return $status; } + //This function restores the glossary_alias table + function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the comments array + $aliases = $info['#']['ALIASES']['0']['#']['ALIAS']; + + //Iterate over comments + for($i = 0; $i < sizeof($aliases); $i++) { + $alias_info = $aliases[$i]; + + //Now, build the GLOSSARY_ALIAS record structure + $alias->entryid = $new_entry_id; + $alias->name = backup_todb($alias_info['#']['NAME']['0']['#']); + + //The structure is equal to the db, so insert the glossary_comments + $newid = insert_record ("glossary_alias",$alias); + + //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 restores the glossary_categories function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) { -- 2.39.5