Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

backup MDL-26572 made restore store null instead of 0

  • Loading branch information...
commit 98529b009b872d6ac6d905201d17441a1f6b2aee 1 parent 2b37004
@andyjdavis andyjdavis authored
View
37 backup/moodle2/restore_stepslib.php
@@ -148,14 +148,14 @@ protected function process_grade_item($data) {
//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 @@ protected function process_grade_item($data) {
$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 @@ protected function process_grade_grade($data) {
$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 @@ protected function after_execute() {
}
}
$rs->close();
+
+ //Restore marks items as needing update. Update everything now.
+ grade_regrade_final_grades($this->get_courseid());
}
}
View
8 backup/util/plan/restore_structure_step.class.php
@@ -196,11 +196,13 @@ public function get_new_parentid($itemname) {
/**
* 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;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.