From: stronk7 Date: Sat, 22 Nov 2003 20:02:34 +0000 (+0000) Subject: Now glossary_ratings are in backup/restore too. !! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5e4f44b6ad516632e7fa3ed916132748f5e56f03;p=moodle.git Now glossary_ratings are in backup/restore too. !! Solved one errors with glossary_alias. Updated "graphical structure" of the module. --- diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index 1285f9b3e8..8aec045647 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -4,18 +4,19 @@ //This is the "graphical" structure of the glossary mod: // - // glossary ---------------------- glossary_categories - // (CL,pk->id) (CL,pk->id,fk->glossaryid) - // | | - // | | - // | | - // glossary_entries -------------- glossary_entries_categories - // (UL,pk->id, fk->glossaryid, files) (UL, pk->categoryid,entryid] - // | \ - // | \ - // | \ - // glossary_comments --------- glossary_alias - // (UL,pk->id, fk->entryid) (UL, pk->id, pk->entryid) + // glossary ----------------------------------------- glossary_categories + // (CL,pk->id) (CL,pk->id,fk->glossaryid) + // | | + // | | + // | | + // glossary_entries --------------------------------glossary_entries_categories + // (UL,pk->id, fk->glossaryid, files) | (UL, pk->categoryid,entryid) + // | | + // | |--------------------glossary_ratings + // | | (UL, pk->id, pk->entryid) + // glossary_comments | + // (UL,pk->id, fk->entryid) |---------------------glossary_alias + // (UL, pk->id, pk->entryid) // // // Meaning: pk->primary key field of the table @@ -171,6 +172,7 @@ if ( $userinfo ) { $status = backup_glossary_comments ($bf,$preferences,$glo_ent->id); + $status = backup_glossary_ratings ($bf,$preferences,$glo_ent->id); } $status =fwrite ($bf,end_tag("ENTRY",5,true)); @@ -214,6 +216,31 @@ } return $status; } + + //Backup glossary_ratings contents (executed from backup_glossary_entries) + function backup_glossary_ratings ($bf,$preferences,$entryid) { + + global $CFG; + + $status = true; + + $ratings = get_records("glossary_ratings","entryid",$entryid); + if ($ratings) { + $status =fwrite ($bf,start_tag("RATINGS",6,true)); + foreach ($ratings as $rating) { + $status =fwrite ($bf,start_tag("RATING",7,true)); + + fwrite ($bf,full_tag("ID",8,false,$rating->id)); + fwrite ($bf,full_tag("USERID",8,false,$rating->userid)); + fwrite ($bf,full_tag("TIME",8,false,$rating->time)); + fwrite ($bf,full_tag("RATING",8,false,$rating->rating)); + + $status =fwrite ($bf,end_tag("RATING",7,true)); + } + $status =fwrite ($bf,end_tag("RATINGS",6,true)); + } + return $status; + } //Backup glossary_alias contents (executed from backup_glossary_entries) function backup_glossary_aliases ($bf,$preferences,$entryid) { @@ -228,7 +255,7 @@ foreach ($aliases as $alias) { $status =fwrite ($bf,start_tag("ALIAS",7,true)); - fwrite ($bf,full_tag("NAME",8,false,$comment->id)); + fwrite ($bf,full_tag("ALIAS_TEXT",8,false,$alias->alias)); $status =fwrite ($bf,end_tag("ALIAS",7,true)); } diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index 09260270bb..cff7b76fc3 100644 --- a/mod/glossary/restorelib.php +++ b/mod/glossary/restorelib.php @@ -4,18 +4,19 @@ //This is the "graphical" structure of the glossary mod: // - // glossary ---------------------- glossary_categories - // (CL,pk->id) (CL,pk->id,fk->glossaryid) - // | | - // | | - // | | - // glossary_entries -------------- glossary_entries_categories - // (UL,pk->id, fk->glossaryid, files) (UL, [pk->categoryid,entryid] - // | \ - // | \ - // | \ - // glossary_comments ------ glossary_alias - // (UL,pk->id, fk->entryid) (UL, pk->id, pk->entryid) + // glossary ----------------------------------------- glossary_categories + // (CL,pk->id) (CL,pk->id,fk->glossaryid) + // | | + // | | + // | | + // glossary_entries --------------------------------glossary_entries_categories + // (UL,pk->id, fk->glossaryid, files) | (UL, pk->categoryid,entryid) + // | | + // | |--------------------glossary_ratings + // | | (UL, pk->id, pk->entryid) + // glossary_comments | + // (UL,pk->id, fk->entryid) |---------------------glossary_alias + // (UL, pk->id, pk->entryid) // // // Meaning: pk->primary key field of the table @@ -172,6 +173,8 @@ $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 restore glossary_ratings + $status = glossary_ratings_restore_mods($oldid,$newid,$ent_info,$restore); //Now copy moddata associated files if needed if ($entry->attachment) { $status = glossary_restore_files ($old_glossary_id, $new_glossary_id, @@ -236,6 +239,55 @@ return $status; } + //This function restores the glossary_ratings + function glossary_ratings_restore_mods($old_entry_id,$new_entry_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the ratings array + $ratings = $info['#']['RATINGS']['0']['#']['RATING']; + + //Iterate over ratings + for($i = 0; $i < sizeof($ratings); $i++) { + $rat_info = $ratings[$i]; + //traverse_xmlize($rat_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //Now, build the GLOSSARY_RATINGS record structure + $rating->entryid = $new_entry_id; + $rating->userid = backup_todb($rat_info['#']['USERID']['0']['#']); + $rating->time = backup_todb($rat_info['#']['TIME']['0']['#']); + $rating->rating = backup_todb($rat_info['#']['RATING']['0']['#']); + + //We have to recode the userid field + $user = backup_getid($restore->backup_unique_code,"user",$rating->userid); + if ($user) { + $rating->userid = $user->new_id; + } + + //The structure is equal to the db, so insert the glossary_ratings + $newid = insert_record ("glossary_ratings",$rating); + + //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_alias table function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore) { @@ -252,7 +304,7 @@ //Now, build the GLOSSARY_ALIAS record structure $alias->entryid = $new_entry_id; - $alias->name = backup_todb($alias_info['#']['NAME']['0']['#']); + $alias->alias = backup_todb($alias_info['#']['ALIAS_TEXT']['0']['#']); //The structure is equal to the db, so insert the glossary_comments $newid = insert_record ("glossary_alias",$alias);