Skip to content

Commit

Permalink
Now glossary_ratings are in backup/restore too. !!
Browse files Browse the repository at this point in the history
Solved one errors with glossary_alias.
Updated "graphical structure" of the module.
  • Loading branch information
stronk7 committed Nov 22, 2003
1 parent 4708a37 commit 5e4f44b
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 26 deletions.
53 changes: 40 additions & 13 deletions mod/glossary/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -171,6 +172,7 @@ function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {

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));
Expand Down Expand Up @@ -214,6 +216,31 @@ function backup_glossary_comments ($bf,$preferences,$entryid) {
}
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) {
Expand All @@ -228,7 +255,7 @@ function backup_glossary_aliases ($bf,$preferences,$entryid) {
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));
}
Expand Down
78 changes: 65 additions & 13 deletions mod/glossary/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,6 +173,8 @@ function glossary_entries_restore_mods($old_glossary_id,$new_glossary_id,$info,$
$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,
Expand Down Expand Up @@ -236,6 +239,55 @@ function glossary_comments_restore_mods($old_entry_id,$new_entry_id,$info,$resto
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 "<br>";
}
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) {

Expand All @@ -252,7 +304,7 @@ function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore)

//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);
Expand Down

0 comments on commit 5e4f44b

Please sign in to comment.