From 48ca6fd871e8a34bcdc097e7f59dca7a0a9963d8 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 30 May 2007 06:38:23 +0000 Subject: [PATCH] fix ordering bug when restoring grade item --- backup/restorelib.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/backup/restorelib.php b/backup/restorelib.php index 67ed3d6e60..dfdb4a7986 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1352,18 +1352,28 @@ $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']['#']); + $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); + + // get the old mod + $mod = get_record('course_module', 'id', $iteminstance); + $modt = get_record('modules', 'id', $mod->module); + if (!restore_userdata_selected($restore, $modt->name, $mod->id)) { - // module instance not restored using granular + // module instance not selected when restored using granular + // skip this item $counteritems++; continue; } + + // iteminstance should point to new mod + $dbrec->iteminstance = backup_getid($restore->backup_unique_code,'course_modules', $iteminstance); + + } else if ($dbrec->itemtype == 'category') { + // the item instance should point to the new grade category + $dbrec->iteminstance = backup_getid($restore->backup_unique_code,'grade_categories', $iteminstance); } $dbrec->itemnumber = backup_todb($info['GRADE_ITEM']['#']['ITEMNUMBER']['0']['#']); -- 2.39.5