Skip to content
Browse files

MDL-28180 backup - on restore always prevent completion_aggr_methd dupes

This covers the last case where dupes could be happening in the
completion_aggr_methd table: Restoring one complete course into
an existing one, adding information. Now we always check if the
aggr_method exists before inserting it.
  • Loading branch information...
1 parent cc2a5ff commit 54c5b28e691eba5f5974f1cbc457eb463ecb77c3 @stronk7 stronk7 committed
Showing with 13 additions and 8 deletions.
  1. +13 −8 backup/moodle2/restore_stepslib.php
View
21 backup/moodle2/restore_stepslib.php
@@ -1741,15 +1741,20 @@ public function process_course_completion_aggr_methd($data) {
$data->course = $this->get_courseid();
- $params = array(
- 'course' => $data->course,
- 'criteriatype' => $data->criteriatype,
- 'method' => $data->method,
- 'value' => $data->value,
- );
- $DB->insert_record('course_completion_aggr_methd', $params);
+ // Only create the course_completion_aggr_methd records if
+ // the target course has not them defined. MDL-28180
+ if (!$DB->record_exists('course_completion_aggr_methd', array(
+ 'course' => $data->course,
+ 'criteriatype' => $data->criteriatype))) {
+ $params = array(
+ 'course' => $data->course,
+ 'criteriatype' => $data->criteriatype,
+ 'method' => $data->method,
+ 'value' => $data->value,
+ );
+ $DB->insert_record('course_completion_aggr_methd', $params);
+ }
}
-
}

0 comments on commit 54c5b28

Please sign in to comment.
Something went wrong with that request. Please try again.