respecting sortorder when restoring grade_itmes, other minor fixes

This commit is contained in:
toyomoyo 2007-05-30 05:32:47 +00:00
parent a3d5594248
commit bb15b33bf9
2 changed files with 37 additions and 17 deletions

View File

@ -1416,9 +1416,12 @@
$status = true;
// get all the grade_items
// might need to do it using sortorder
if ($grade_items = get_records('grade_items', 'courseid', $preferences->backup_course)) {
// get all the grade_items, ordered by sort order since upon restoring, it is not always
// possible to use the same sort order. We could at least preserve the sortorder by restoring
// grade_items in the original sortorder
if ($grade_items = get_records_sql("SELECT * FROM {$CFG->prefix}grade_items
WHERE courseid = $preferences->backup_course
ORDER BY sortorder ASC")) {
//Begin grade_items tag
fwrite ($bf,start_tag("GRADE_ITEMS",3,true));
@ -1603,15 +1606,15 @@
foreach ($histories as $history) {
fwrite ($bf,start_tag("GRADE_HISTORY",6,true));
fwrite ($bf,full_tag("ID",7,false,$history->id));
fwrite ($bf,full_tag("USERID",7,false,$hisotry->userid));
fwrite ($bf,full_tag("OLDGRADE",7,false,$hisotry->oldgrade));
fwrite ($bf,full_tag("USERID",7,false,$history->userid));
fwrite ($bf,full_tag("OLDGRADE",7,false,$history->oldgrade));
fwrite ($bf,full_tag("NEWGRADE",7,false,$history->newgrade));
fwrite ($bf,full_tag("NOTE",7,false,$history->note));
fwrite ($bf,full_tag("HOWMODIFIED",7,false,$hisotry->howmodified));
fwrite ($bf,full_tag("USERMODIFIED",7,false,$hisotry->usermodified));
fwrite ($bf,full_tag("HOWMODIFIED",7,false,$history->howmodified));
fwrite ($bf,full_tag("USERMODIFIED",7,false,$history->usermodified));
fwrite ($bf,end_tag("GRADE_HISTORY",6,true));
}
$stauts = fwrite ($bf,end_tag("GRADE_GRADES_HISOTRY",5,true));
$stauts = fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",5,true));
}
return $status;
}

View File

@ -1320,13 +1320,14 @@
echo '<li>'.get_string('gradeitems','grades').'</li>';
}
$counter = 0;
$countercat = 0;
while ($countercat < $itemscount) {
$counteritems = 0;
while ($counteritems < $itemscount) {
//Fetch recordset_size records in each iteration
$recs = get_records_select("backup_ids","table_name = 'grade_items' AND backup_code = '$restore->backup_unique_code'",
"old_id",
"old_id, old_id",
$countercat,
$counteritems,
$recordset_size);
if ($recs) {
foreach ($recs as $rec) {
@ -1341,7 +1342,7 @@
$dbrec->courseid = $restore->course_id;
if ($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#']) {
if (!empty($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#'])) {
$dbrec->categoryid = backup_getid($restore->backup_unique_code,'grade_categories',backup_todb($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#']));
}
@ -1389,7 +1390,22 @@
*/
// always insert, since modules restored to existing courses are always inserted
$itemid = insert_record('grade_items',$dbrec);
// get the current sortorder, add 1 to it and use that
if ($lastitem = get_record_sql("SELECT sortorder, id FROM {$CFG->prefix}grade_items
WHERE courseid = $restore->course_id
ORDER BY sortorder DESC ", true)) {
// we just need the first one
$dbrec->sortorder = $lastitem->sortorder + 1;
} else {
// this is the first grade_item
$dbrec->sortorder = 0;
}
$itemid = insert_record('grade_items',$dbrec);
/// now, restore grade_calculations, grade_raw, grade_final, grade_text, and grade_history
if (!empty($info['GRADE_ITEM']['#']['GRADE_GRADES_RAW']['0']['#']) && ($raws = $info['GRADE_ITEM']['#']['GRADE_GRADES_RAW']['0']['#']['GRADE_RAW'])) {
//Iterate over items
@ -1506,9 +1522,9 @@
$text->informationformat = backup_todb($ite_info['#']['INFORMATIONFORMAT']['0']['#']);
$text->feedback = backup_todb($ite_info['#']['FEEDBACK']['0']['#']);
$text->feedbackformat = backup_todb($ite_info['#']['FEEDBACKFORMAT']['0']['#']);
insert_record('grade_grades_text', $text);
$counter++;
if ($counter % 20 == 0) {
if (!defined('RESTORE_SILENTLY')) {
@ -1539,7 +1555,7 @@
$history->howmodified = backup_todb($ite_info['#']['HOWMODIFIED']['0']['#']);
$modifier = backup_getid($restore->backup_unique_code,"user", backup_todb($ite_info['#']['USERMODIFIED']['0']['#']));
$history->usermodified = $modifier->new_id;
insert_record('grade_history', $text);
insert_record('grade_history', $history);
$counter++;
if ($counter % 20 == 0) {
@ -1554,9 +1570,10 @@
}
}
}
$counteritems++; // increment item count
}
}
$countercat++;
}
}