MDL-47076 badges: Add checks to user fields during badges restoration

Change-Id: Iff6402d1da835ed57dc17d079adf1bbd2e76dd6c
This commit is contained in:
David Curry 2014-09-03 15:51:22 +12:00
parent 457f818026
commit 927ea484ec

View file

@ -2114,7 +2114,13 @@ class restore_badges_structure_step extends restore_structure_step {
$data = (object)$data; $data = (object)$data;
$data->usercreated = $this->get_mappingid('user', $data->usercreated); $data->usercreated = $this->get_mappingid('user', $data->usercreated);
if (empty($data->usercreated)) {
$data->usercreated = $this->task->get_userid();
}
$data->usermodified = $this->get_mappingid('user', $data->usermodified); $data->usermodified = $this->get_mappingid('user', $data->usermodified);
if (empty($data->usermodified)) {
$data->usermodified = $this->task->get_userid();
}
// We'll restore the badge image. // We'll restore the badge image.
$restorefiles = true; $restorefiles = true;
@ -2211,6 +2217,12 @@ class restore_badges_structure_step extends restore_structure_step {
'issuerrole' => $role, 'issuerrole' => $role,
'datemet' => $this->apply_date_offset($data->datemet) 'datemet' => $this->apply_date_offset($data->datemet)
); );
// Skip the manual award if recipient or issuer can not be mapped to.
if (empty($award['recipientid']) || empty($award['issuerid'])) {
return;
}
$DB->insert_record('badge_manual_award', $award); $DB->insert_record('badge_manual_award', $award);
} }
} }