Permalink
Browse files

MDL-33455 restore: process grade_grades only if user matches.

Note this has been applied both to individual activities grade_grades
and to general ones.
  • Loading branch information...
1 parent 887e2c8 commit 75bb216d66a05488adc6d5d29274b90acb12e426 @stronk7 stronk7 committed with nebgor Jun 10, 2012
Showing with 22 additions and 15 deletions.
  1. +22 −15 backup/moodle2/restore_stepslib.php
@@ -206,13 +206,13 @@ protected function process_grade_grade($data) {
global $DB;
$data = (object)$data;
- $oldid = $data->id;
+ $olduserid = $data->userid;
$data->itemid = $this->get_new_parentid('grade_item');
- $data->userid = $this->get_mappingid('user', $data->userid, NULL);
- if (!is_null($data->userid)) {
- $data->usermodified = $this->get_mappingid('user', $data->usermodified, NULL);
+ $data->userid = $this->get_mappingid('user', $data->userid, null);
+ if (!empty($data->userid)) {
+ $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);
@@ -221,9 +221,10 @@ protected function process_grade_grade($data) {
$newitemid = $DB->insert_record('grade_grades', $data);
} else {
- debugging("Mapped user id not found for grade item id '{$data->itemid}'");
+ debugging("Mapped user id not found for user id '{$olduserid}', grade item id '{$data->itemid}'");
}
}
+
protected function process_grade_category($data) {
global $DB;
@@ -2225,18 +2226,24 @@ protected function process_grade_item($data) {
protected function process_grade_grade($data) {
$data = (object)($data);
-
+ $olduserid = $data->userid;
unset($data->id);
+
$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->rawscaleid = $this->get_mappingid('scale', $data->rawscaleid);
- // TODO: Ask, all the rest of locktime/exported... work with time... to be rolled?
- $data->overridden = $this->apply_date_offset($data->overridden);
-
- $grade = new grade_grade($data, false);
- $grade->insert('restore');
- // no need to save any grade_grade mapping
+
+ $data->userid = $this->get_mappingid('user', $data->userid, null);
+ if (!empty($data->userid)) {
+ $data->usermodified = $this->get_mappingid('user', $data->usermodified, null);
+ $data->rawscaleid = $this->get_mappingid('scale', $data->rawscaleid);
+ // TODO: Ask, all the rest of locktime/exported... work with time... to be rolled?
+ $data->overridden = $this->apply_date_offset($data->overridden);
+
+ $grade = new grade_grade($data, false);
+ $grade->insert('restore');
+ // no need to save any grade_grade mapping
+ } else {
+ debugging("Mapped user id not found for user id '{$olduserid}', grade item id '{$data->itemid}'");
+ }
}
/**

0 comments on commit 75bb216

Please sign in to comment.