Permalink
Browse files

Now forum_read is included in backup & restore

  • Loading branch information...
stronk7
stronk7 committed Feb 18, 2005
1 parent f0195f0 commit 22bb909b5785a6f94c7459efffc42486af819a1b
Showing with 159 additions and 36 deletions.
  1. +1 −1 backup/CHANGES_14_15.txt
  2. +1 −1 backup/version.php
  3. +53 −17 mod/forum/backuplib.php
  4. +104 −17 mod/forum/restorelib.php
View
@@ -39,7 +39,7 @@ Now I show the specific detailed status of every item in the process:
23. DONE: Add support for metacourses in backup and restore. Show a new option
to decide what to do (ignore, process).
24. DONE: Take out THEME from backup directory.
25. TODO: Add support for forum_read table in backup and restore.
25. DONE: Add support for forum_read table in backup and restore.
26. DONE: chat_users->course and chat_users->lang. No changes required!
27. PROG: Make the backup/restore/config/logs/index.php XHTML 1.0 Transitional.
Done in manual backups, config, logs and restore.
View
@@ -5,6 +5,6 @@
// database (backup_version) to determine whether upgrades should
// be performed (see db/backup_*.php)
$backup_version = 2005021300; // The current version is a date (YYYYMMDDXX)
$backup_version = 2005021800; // The current version is a date (YYYYMMDDXX)
$backup_release = "1.5 development"; // User-friendly version number
View
@@ -4,23 +4,24 @@
//This is the "graphical" structure of the forum mod:
//
// forum
// (CL,pk->id)
// |
// -----------------------------------
// | |
// subscriptions forum_discussions
// (UL,pk->id, fk->forum) (UL,pk->id, fk->forum)
// |
// |
// |
// forum_posts
// (UL,pk->id,fk->discussion,nt->parent,files)
// |
// |
// |
// forum_ratings
// (UL,pk->id,fk->post)
// forum
// (CL,pk->id)
// |
// ---------------------------------------------------
// | |
// subscriptions forum_discussions
//(UL,pk->id, fk->forum) ---------------(UL,pk->id, fk->forum)
// | |
// | |
// | |
// | forum_posts
// |-------------(UL,pk->id,fk->discussion,
// | nt->parent,files)
// | |
// | |
// | |
// forum_read forum_ratings
// (UL,pk->id,fk->post (UL,pk->id,fk->post)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
@@ -68,6 +69,9 @@ function forum_backup_mods($bf,$preferences) {
if ($status) {
$status = backup_forum_discussions($bf,$preferences,$forum->id);
}
if ($status) {
$status = backup_forum_read($bf,$preferences,$forum->id);
}
}
//End mod
$status =fwrite ($bf,end_tag("MOD",3,true));
@@ -146,6 +150,38 @@ function backup_forum_discussions ($bf,$preferences,$forum) {
return $status;
}
//Backup forum_read contents (executed from forum_backup_mods)
function backup_forum_read ($bf,$preferences,$forum) {
global $CFG;
$status = true;
$forum_read = get_records("forum_read","forumid",$forum,"id");
//If there are read
if ($forum_read) {
//Write start tag
$status =fwrite ($bf,start_tag("READPOSTS",4,true));
//Iterate over each read
foreach ($forum_read as $for_rea) {
//Start read
$status =fwrite ($bf,start_tag("READ",5,true));
//Print forum_read contents
fwrite ($bf,full_tag("ID",6,false,$for_rea->id));
fwrite ($bf,full_tag("USERID",6,false,$for_rea->userid));
fwrite ($bf,full_tag("DISCUSSIONID",6,false,$for_rea->discussionid));
fwrite ($bf,full_tag("POSTID",6,false,$for_rea->postid));
fwrite ($bf,full_tag("FIRSTREAD",6,false,$for_rea->firstread));
fwrite ($bf,full_tag("LASTREAD",6,false,$for_rea->lastread));
//End read
$status =fwrite ($bf,end_tag("READ",5,true));
}
//Write end tag
$status =fwrite ($bf,end_tag("READPOSTS",4,true));
}
return $status;
}
//Backup forum_posts contents (executed from backup_forum_discussions)
function backup_forum_posts ($bf,$preferences,$discussion) {
View
@@ -4,23 +4,24 @@
//This is the "graphical" structure of the forum mod:
//
// forum
// (CL,pk->id)
// |
// -----------------------------------
// | |
// subscriptions forum_discussions
// (UL,pk->id, fk->forum) (UL,pk->id, fk->forum)
// |
// |
// |
// forum_posts
// (UL,pk->id,fk->discussion,nt->parent,files)
// |
// |
// |
// forum_ratings
// (UL,pk->id,fk->post)
// forum
// (CL,pk->id)
// |
// ---------------------------------------------------
// | |
// subscriptions forum_discussions
//(UL,pk->id, fk->forum) ---------------(UL,pk->id, fk->forum)
// | |
// | |
// | |
// | forum_posts
// |-------------(UL,pk->id,fk->discussion,
// | nt->parent,files)
// | |
// | |
// | |
// forum_read forum_ratings
// (UL,pk->id,fk->post (UL,pk->id,fk->post)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
@@ -105,6 +106,10 @@ function forum_restore_mods($mod,$restore) {
//Restore forum_discussions
$status = forum_discussions_restore_mods ($newid,$info,$restore);
}
if ($status) {
//Restore forum_read
$status = forum_read_restore_mods ($newid,$info,$restore);
}
}
} else {
$status = false;
@@ -268,6 +273,88 @@ function forum_discussions_restore_mods($forum_id,$info,$restore) {
return $status;
}
//This function restores the forum_read
function forum_read_restore_mods($forum_id,$info,$restore) {
global $CFG;
$status = true;
//Get the read array
$readposts = $info['MOD']['#']['READPOSTS']['0']['#']['READ'];
//Iterate over readposts
for($i = 0; $i < sizeof($readposts); $i++) {
$rea_info = $readposts[$i];
//traverse_xmlize($rea_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//We'll need this later!!
$oldid = backup_todb($rea_info['#']['ID']['0']['#']);
//Now, build the FORUM_READ record structure
$read->forumid = $forum_id;
$read->userid = backup_todb($rea_info['#']['USERID']['0']['#']);
$read->discussionid = backup_todb($rea_info['#']['DISCUSSIONID']['0']['#']);
$read->postid = backup_todb($rea_info['#']['POSTID']['0']['#']);
$read->firstread = backup_todb($rea_info['#']['FIRSTREAD']['0']['#']);
$read->lastread = backup_todb($rea_info['#']['LASTREAD']['0']['#']);
//Some recoding and check are performed now
$toinsert = true;
//We have to recode the userid field
$user = backup_getid($restore->backup_unique_code,"user",$read->userid);
if ($user) {
$read->userid = $user->new_id;
} else {
$toinsert = false;
}
//We have to recode the discussionid field
$discussion = backup_getid($restore->backup_unique_code,"forum_discussions",$read->discussionid);
if ($discussion) {
$read->discussionid = $discussion->new_id;
} else {
$toinsert = false;
}
//We have to recode the postid field
$post = backup_getid($restore->backup_unique_code,"forum_posts",$read->postid);
if ($post) {
$read->postid = $post->new_id;
} else {
$toinsert = false;
}
//The structure is equal to the db, so insert the forum_read
$newid = 0;
if ($toinsert) {
$newid = insert_record ("forum_read",$read);
}
//Do some output
if (($i+1) % 50 == 0) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
backup_flush(300);
}
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"forum_read",$oldid,
$newid);
} else {
$status = false;
}
}
return $status;
}
//This function restores the forum_posts
function forum_posts_restore_mods($new_forum_id,$discussion_id,$info,$restore) {

0 comments on commit 22bb909

Please sign in to comment.