Merge branch 'MDL-26572_backup_sum' of git://github.com/andyjdavis/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2011-03-07 00:10:16 +01:00
commit 07a36633f9
2 changed files with 22 additions and 21 deletions

View File

@ -148,14 +148,14 @@ class restore_gradebook_structure_step extends restore_structure_step {
//manual grade items store category id in categoryid
if ($data->itemtype=='manual') {
$data->categoryid = $this->get_mappingid('grade_category', $data->categoryid);
$data->categoryid = $this->get_mappingid('grade_category', $data->categoryid, NULL);
} //course and category grade items store their category id in iteminstance
else if ($data->itemtype=='course' || $data->itemtype=='category') {
$data->iteminstance = $this->get_mappingid('grade_category', $data->iteminstance);
$data->iteminstance = $this->get_mappingid('grade_category', $data->iteminstance, NULL);
}
$data->scaleid = $this->get_mappingid('scale', $data->scaleid);
$data->outcomeid = $this->get_mappingid('outcome', $data->outcomeid);
$data->scaleid = $this->get_mappingid('scale', $data->scaleid, NULL);
$data->outcomeid = $this->get_mappingid('outcome', $data->outcomeid, NULL);
$data->locktime = $this->apply_date_offset($data->locktime);
$data->timecreated = $this->apply_date_offset($data->timecreated);
@ -164,23 +164,19 @@ class restore_gradebook_structure_step extends restore_structure_step {
$coursecategory = $newitemid = null;
//course grade item should already exist so updating instead of inserting
if($data->itemtype=='course') {
//get the ID of the already created grade item
$gi = new stdclass();
$gi->courseid = $this->get_courseid();
$gi->itemtype = $data->itemtype;
if ($data->itemtype=='course') {
//need to get the id of the grade_category that was automatically created for the course
$category = new stdclass();
$category->courseid = $this->get_courseid();
$category->parent = null;
//course category fullname starts out as ? but may be edited
//$category->fullname = '?';
$coursecategory = $DB->get_record('grade_categories', (array)$category);
$gi->iteminstance = $coursecategory->id;
}
//need to get the id of the grade_category that was automatically created for the course
$category = new stdclass();
$category->courseid = $this->get_courseid();
$category->parent = null;
//course category fullname starts out as ? but may be edited
//$category->fullname = '?';
$coursecategory = $DB->get_record('grade_categories', (array)$category);
$gi->iteminstance = $coursecategory->id;
$existinggradeitem = $DB->get_record('grade_items', (array)$gi);
if (!empty($existinggradeitem)) {
@ -208,8 +204,8 @@ class restore_gradebook_structure_step extends restore_structure_step {
$data->itemid = $this->get_new_parentid('grade_item');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->usermodified = $this->get_mappingid('user', $data->usermodified);
$data->userid = $this->get_mappingid('user', $data->userid, NULL);
$data->usermodified = $this->get_mappingid('user', $data->usermodified, NULL);
$data->locktime = $this->apply_date_offset($data->locktime);
// TODO: Ask, all the rest of locktime/exported... work with time... to be rolled?
$data->overridden = $this->apply_date_offset($data->overridden);
@ -337,6 +333,9 @@ class restore_gradebook_structure_step extends restore_structure_step {
}
}
$rs->close();
//Restore marks items as needing update. Update everything now.
grade_regrade_final_grades($this->get_courseid());
}
}

View File

@ -196,11 +196,13 @@ abstract class restore_structure_step extends restore_step {
/**
* Return the new id of a mapping for the given itemname
*
* @param string $itemname the type of item. For example 'scale' or 'outcome'
* @param int $oldid the item ID from the backup
* @param $ifnotfound what to return if $oldid wasnt found
*/
public function get_mappingid($itemname, $oldid) {
public function get_mappingid($itemname, $oldid, $ifnotfound = false) {
$mapping = $this->get_mapping($itemname, $oldid);
return $mapping ? $mapping->newitemid : false;
return $mapping ? $mapping->newitemid : $ifnotfound;
}
/**