Skip to content

Commit

Permalink
MDL-33455 restore: process grade_grades only if user matches.
Browse files Browse the repository at this point in the history
Note this has been applied both to individual activities grade_grades
and to general ones.
  • Loading branch information
stronk7 authored and Aparup Banerjee committed Jun 11, 2012
1 parent 34025ea commit 294e7ff
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -2043,18 +2044,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}'");
}
}

/**
Expand Down

0 comments on commit 294e7ff

Please sign in to comment.