require_once($CFG->libdir . '/db/upgradelib.php');
upgrade_extra_credit_weightoverride($this->get_courseid());
}
+ // Calculated grade items need recalculating for backups made between 2.8 release (20141110) and the fix release (20150627).
+ if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150627) {
+ require_once($CFG->libdir . '/db/upgradelib.php');
+ upgrade_calculated_grade_items($this->get_courseid());
+ }
}
+
+ /**
+ * Checks what should happen with the course grade setting minmaxtouse.
+ *
+ * This is related to the upgrade step at the time the setting was added.
+ *
+ * @see MDL-48618
+ * @return void
+ */
+ protected function check_minmaxtouse() {
+ global $CFG, $DB;
+ require_once($CFG->libdir . '/gradelib.php');
+
+ $userinfo = $this->task->get_setting_value('users');
+ $settingname = 'minmaxtouse';
+ $courseid = $this->get_courseid();
+ $minmaxtouse = $DB->get_field('grade_settings', 'value', array('courseid' => $courseid, 'name' => $settingname));
+ $version28start = 2014111000.00;
+ $version28last = 2014111006.05;
+ $version29start = 2015051100.00;
+ $version29last = 2015060400.02;
+
+ $target = $this->get_task()->get_target();
+ if ($minmaxtouse === false &&
+ ($target != backup::TARGET_CURRENT_ADDING && $target != backup::TARGET_EXISTING_ADDING)) {
+ // The setting was not found because this setting did not exist at the time the backup was made.
+ // And we are not restoring as merge, in which case we leave the course as it was.
+ $version = $this->get_task()->get_info()->moodle_version;
+
+ if ($version < $version28start) {
+ // We need to set it to use grade_item, but only if the site-wide setting is different. No need to notice them.
+ if ($CFG->grade_minmaxtouse != GRADE_MIN_MAX_FROM_GRADE_ITEM) {
+ grade_set_setting($courseid, $settingname, GRADE_MIN_MAX_FROM_GRADE_ITEM);
+ }
+
+ } else if (($version >= $version28start && $version < $version28last) ||
+ ($version >= $version29start && $version < $version29last)) {
+ // They should be using grade_grade when the course has inconsistencies.
+
+ $sql = "SELECT gi.id
+ FROM {grade_items} gi
+ JOIN {grade_grades} gg
+ ON gg.itemid = gi.id
+ WHERE gi.courseid = ?
+ AND (gi.itemtype != ? AND gi.itemtype != ?)
+ AND (gg.rawgrademax != gi.grademax OR gg.rawgrademin != gi.grademin)";
+
+ // The course can only have inconsistencies when we restore the user info,
+ // we do not need to act on existing grades that were not restored as part of this backup.
+ if ($userinfo && $DB->record_exists_sql($sql, array($courseid, 'course', 'category'))) {
+
+ // Display the notice as we do during upgrade.
+ set_config('show_min_max_grades_changed_' . $courseid, 1);
+
+ if ($CFG->grade_minmaxtouse != GRADE_MIN_MAX_FROM_GRADE_GRADE) {
+ // We need set the setting as their site-wise setting is not GRADE_MIN_MAX_FROM_GRADE_GRADE.
+ // If they are using the site-wide grade_grade setting, we only want to notice them.
+ grade_set_setting($courseid, $settingname, GRADE_MIN_MAX_FROM_GRADE_GRADE);
+ }
+ }
+
+ } else {
+ // This should never happen because from now on minmaxtouse is always saved in backups.
+ }
+ }
+ }
}
/**