Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-29598 backup Avoid possible future duplicate grade letters

More info in restore_activity_grades_structure_step->process_grade_letter() comments
  • Loading branch information...
commit b7da14f1c628b49c665438e734a10e192c0435b2 1 parent 44ec173
@dmonllao dmonllao authored
Showing with 11 additions and 8 deletions.
  1. +11 −8 backup/moodle2/restore_stepslib.php
View
19 backup/moodle2/restore_stepslib.php
@@ -270,10 +270,9 @@ protected function process_grade_letter($data) {
$data->contextid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
- // MDL-29598 - Don't insert a duplicate record if this grade letter already exists
- $gltest = (array)$data;
- unset($gltest['id']);
- if (!$DB->record_exists('grade_letters', $gltest)) {
+ $gradeletter = (array)$data;
+ unset($gradeletter['id']);
+ if (!$DB->record_exists('grade_letters', $gradeletter)) {
$newitemid = $DB->insert_record('grade_letters', $data);
} else {
$newitemid = $data->id;
@@ -2409,17 +2408,21 @@ protected function process_grade_grade($data) {
/**
* process activity grade_letters. Note that, while these are possible,
- * because grade_letters are contextid based, in proctice, only course
+ * because grade_letters are contextid based, in practice, only course
* context letters can be defined. So we keep here this method knowing
* it won't be executed ever. gradebook restore will restore course letters.
*/
protected function process_grade_letter($data) {
global $DB;
- $data = (object)$data;
+ $data['contextid'] = $this->task->get_contextid();
+ $gradeletter = (object)$data;
- $data->contextid = $this->task->get_contextid();
- $newitemid = $DB->insert_record('grade_letters', $data);
+ // Check if it exists before adding it
+ unset($data['id']);
+ if (!$DB->record_exists('grade_letters', $data)) {
+ $newitemid = $DB->insert_record('grade_letters', $gradeletter);
+ }
// no need to save any grade_letter mapping
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.