From 9bfd00944115371914675c783c2fac3d7f2b0b95 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 30 May 2007 06:23:21 +0000 Subject: [PATCH] added itemtype to backup/restore, only restore a mod type gradeitem if user data is included --- backup/backuplib.php | 3 ++- backup/restorelib.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backup/backuplib.php b/backup/backuplib.php index 05563c1c11..44c58af548 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1431,8 +1431,9 @@ fwrite ($bf,start_tag("GRADE_ITEM",4,true)); //Output individual fields - fwrite ($bf,full_tag("ID",5,false,$grade_item->id)); + fwrite ($bf,full_tag("ID",5,false,$grade_item->id)); fwrite ($bf,full_tag("ITEMNAME",5,false,$grade_item->itemname)); + fwrite ($bf,full_tag("ITEMTYPE",5,false,$grade_item->itemtype)); fwrite ($bf,full_tag("ITEMMODULE",5,false,$grade_item->itemmodule)); fwrite ($bf,full_tag("ITEMINSTANCE",5,false,$grade_item->iteminstance)); fwrite ($bf,full_tag("ITEMNUMBER",5,false,$grade_item->itemnumber)); diff --git a/backup/restorelib.php b/backup/restorelib.php index 3985cb6dd1..67ed3d6e60 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1334,6 +1334,7 @@ //Get the full record from backup_ids $data = backup_getid($restore->backup_unique_code,'grade_items',$rec->old_id); if ($data) { + //Now get completed xmlized object $info = $data->info; //traverse_xmlize($info); //Debug @@ -1347,10 +1348,24 @@ } $dbrec->itemname = backup_todb($info['GRADE_ITEM']['#']['ITEMNAME']['0']['#']); + $dbrec->itemtype = backup_todb($info['GRADE_ITEM']['#']['ITEMTYPE']['0']['#']); $dbrec->itemmodule = backup_todb($info['GRADE_ITEM']['#']['ITEMMODULE']['0']['#']); /// this needs to point to either the new mod id /// or the category id $dbrec->iteminstance = backup_todb($info['GRADE_ITEM']['#']['ITEMINSTANCE']['0']['#']); + + // do not restore if this grade_item is a mod, and + if ($dbrec->itemtype == 'mod') { + // get the mod + $mod = get_record('course_module', 'id', $dbrec->iteminstance); + $modt = get_record('modules', 'id', $mod->module); + if (!restore_userdata_selected($restore, $modt->name, $mod->id)) { + // module instance not restored using granular + $counteritems++; + continue; + } + } + $dbrec->itemnumber = backup_todb($info['GRADE_ITEM']['#']['ITEMNUMBER']['0']['#']); $dbrec->iteminfo = backup_todb($info['GRADE_ITEM']['#']['ITEMINFO']['0']['#']); $dbrec->idnumber = backup_todb($info['GRADE_ITEM']['#']['IDNUMBER']['0']['#']); -- 2.39.5