From 98529b009b872d6ac6d905201d17441a1f6b2aee Mon Sep 17 00:00:00 2001 From: "Andrew Davis (andyjdavis)" Date: Wed, 2 Mar 2011 10:33:14 +0800 Subject: [PATCH] backup MDL-26572 made restore store null instead of 0 --- backup/moodle2/restore_stepslib.php | 35 +++++++++---------- .../plan/restore_structure_step.class.php | 8 +++-- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index eace0149591..7708d33e994 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -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()); } } diff --git a/backup/util/plan/restore_structure_step.class.php b/backup/util/plan/restore_structure_step.class.php index 970605e2906..927f71c7f01 100644 --- a/backup/util/plan/restore_structure_step.class.php +++ b/backup/util/plan/restore_structure_step.class.php @@ -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; } /**