Merge branch 'MDL-50569-master' of git://github.com/FMCorz/moodle

This commit is contained in:
David Monllao
2015-06-30 09:30:57 +08:00
2 changed files with 92 additions and 2 deletions
+13 -1
View File
@@ -939,6 +939,7 @@ class backup_gradebook_structure_step extends backup_structure_step {
}
protected function define_structure() {
global $CFG, $DB;
// are we including user info?
$userinfo = $this->get_setting_value('users');
@@ -1030,7 +1031,18 @@ class backup_gradebook_structure_step extends backup_structure_step {
$letter->set_source_table('grade_letters', array('contextid' => backup::VAR_CONTEXTID));
$grade_setting->set_source_table('grade_settings', array('courseid' => backup::VAR_COURSEID));
// Set the grade settings source, forcing the inclusion of minmaxtouse if not present.
$settings = array();
$rs = $DB->get_recordset('grade_settings', array('courseid' => $this->get_courseid()));
foreach ($rs as $record) {
$settings[$record->name] = $record;
}
$rs->close();
if (!isset($settings['minmaxtouse'])) {
$settings['minmaxtouse'] = (object) array('name' => 'minmaxtouse', 'value' => $CFG->grade_minmaxtouse);
}
$grade_setting->set_source_array($settings);
// Annotations (both as final as far as they are going to be exported in next steps)
$grade_item->annotate_ids('scalefinal', 'scaleid'); // Straight as scalefinal because it's > 0
+79 -1
View File
@@ -335,13 +335,23 @@ class restore_gradebook_structure_step extends restore_structure_step {
$data->courseid = $this->get_courseid();
$target = $this->get_task()->get_target();
if ($data->name == 'minmaxtouse' &&
($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING)) {
// We never restore minmaxtouse during merge.
return;
}
if (!$DB->record_exists('grade_settings', array('courseid' => $data->courseid, 'name' => $data->name))) {
$newitemid = $DB->insert_record('grade_settings', $data);
} else {
$newitemid = $data->id;
}
$this->set_mapping('grade_setting', $oldid, $newitemid);
if (!empty($oldid)) {
// In rare cases (minmaxtouse), it is possible that there wasn't any ID associated with the setting.
$this->set_mapping('grade_setting', $oldid, $newitemid);
}
}
/**
@@ -463,6 +473,9 @@ class restore_gradebook_structure_step extends restore_structure_step {
}
$rs->close();
// Check what to do with the minmaxtouse setting.
$this->check_minmaxtouse();
// Freeze gradebook calculations if needed.
$this->gradebook_calculation_freeze();
@@ -487,6 +500,71 @@ class restore_gradebook_structure_step extends restore_structure_step {
upgrade_extra_credit_weightoverride($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;
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.
}
}
}
}
/**