- Backup of categories and its entries
- Working on the restore process... Eloy will gives me a hand this (hopefully!)
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
|
||||
//This is the "graphical" structure of the glossary mod:
|
||||
//
|
||||
// glossary
|
||||
// (CL,pk->id)
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// glossary_entries
|
||||
// (UL,pk->id, fk->glossaryid, files)
|
||||
// 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]
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
@@ -19,7 +19,7 @@
|
||||
// UL->user level info
|
||||
// files->table may have files)
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
function glossary_backup_mods($bf,$preferences) {
|
||||
|
||||
@@ -46,9 +46,11 @@
|
||||
fwrite ($bf,full_tag("SHOWALL",4,false,$glossary->showall));
|
||||
fwrite ($bf,full_tag("TIMECREATED",4,false,$glossary->timecreated));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$glossary->timemodified));
|
||||
|
||||
|
||||
backup_glossary_entries($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo);
|
||||
|
||||
backup_glossary_categories($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo);
|
||||
|
||||
//End mod
|
||||
$status =fwrite ($bf,end_tag("MOD",3,true));
|
||||
}
|
||||
@@ -56,6 +58,45 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup glossary_categories and entries_categories contents (executed from glossary_backup_mods)
|
||||
function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$glossary_categories = get_records("glossary_categories","glossaryid",$glossary,"id");
|
||||
//If there is submissions
|
||||
if ($glossary_categories) {
|
||||
$status =fwrite ($bf,start_tag("CATEGORIES",4,true));
|
||||
|
||||
//Iterate over each category
|
||||
foreach ($glossary_categories as $glo_cat) {
|
||||
//Start category
|
||||
//Print submission contents
|
||||
$status =fwrite ($bf,start_tag("CATEGORY",5,true));
|
||||
|
||||
fwrite ($bf,full_tag("ID",6,false,$glo_cat->id));
|
||||
fwrite ($bf,full_tag("GLOSSARYID",6,false,$glo_cat->glossaryid));
|
||||
fwrite ($bf,full_tag("NAME",6,false,$glo_cat->name));
|
||||
|
||||
$entries = get_records("glossary_entries_categories","categoryid",$glo_cat->id,"glossaryid");
|
||||
if ($entries) {
|
||||
$status =fwrite ($bf,start_tag("ENTRIES",6,true));
|
||||
foreach ($entries -> $entry) {
|
||||
fwrite ($bf,full_tag("ENTRYID",7,false,$entry->entryid));
|
||||
}
|
||||
$status =fwrite ($bf,end_tag("ENTRIES",6,true));
|
||||
}
|
||||
$status =fwrite ($bf,end_tag("CATEGORY",5,true));
|
||||
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag("CATEGORIES",4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup glossary_entries contents (executed from glossary_backup_mods)
|
||||
function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
//Now check if want to restore user data and do it.
|
||||
//Restore glossary_entries
|
||||
$status = glossary_entries_restore_mods($mod->id,$newid,$info,$restore);
|
||||
// $status = glossary_categories_restore_mods($mod->id,$newid,$info,$restore);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
@@ -146,6 +147,51 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the glossary_categories and entries_categories
|
||||
function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the categories array
|
||||
$categories = $info['MOD']['#']['CATEGORIES']['0']['#']['CATEGORY'];
|
||||
|
||||
//Iterate over entries
|
||||
for($i = 0; $i < sizeof($categories); $i++) {
|
||||
$cat_info = $categories[$i];
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($cat_info['#']['ID']['0']['#']);
|
||||
|
||||
//Now, build the GLOSSARY_CATEGORIES record structure
|
||||
$category->glossaryid = $new_glossary_id;
|
||||
$category->name = backup_todb($cat_info['#']['NAME']['0']['#']);
|
||||
|
||||
$newid = insert_record ("glossary_categories",$category);
|
||||
|
||||
//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,"glossary_categories",$oldid,$newid);
|
||||
//Now copy moddata associated files if needed
|
||||
} else {
|
||||
$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) {
|
||||
|
||||
Reference in New Issue
Block a user