mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-65809 upgrade: remove get_assignments_with_rescaled_null_grades
This function was used only by deleted upgrade steps so it's safe to proceed with straight deletion, considering it internal. Deletion has been documented in corresponding upgrade.txt files.
This commit is contained in:
parent
08bc1f11db
commit
d2b7f6f556
@ -34,108 +34,6 @@ function xmldb_assign_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2017021500) {
|
||||
// Fix event types of assign events.
|
||||
$params = [
|
||||
'modulename' => 'assign',
|
||||
'eventtype' => 'close'
|
||||
];
|
||||
$select = "modulename = :modulename AND eventtype = :eventtype";
|
||||
$DB->set_field_select('event', 'eventtype', 'due', $select, $params);
|
||||
|
||||
// Delete 'open' events.
|
||||
$params = [
|
||||
'modulename' => 'assign',
|
||||
'eventtype' => 'open'
|
||||
];
|
||||
$DB->delete_records('event', $params);
|
||||
|
||||
// Assign savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2017021500, 'assign');
|
||||
}
|
||||
|
||||
if ($oldversion < 2017031300) {
|
||||
// Add a 'gradingduedate' field to the 'assign' table.
|
||||
$table = new xmldb_table('assign');
|
||||
$field = new xmldb_field('gradingduedate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'cutoffdate');
|
||||
|
||||
// Conditionally launch add field.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Assign savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2017031300, 'assign');
|
||||
}
|
||||
|
||||
if ($oldversion < 2017042800) {
|
||||
// Update query to set the grading due date one week after the due date.
|
||||
// Only assign instances with grading due date not set and with a due date of not older than 3 weeks will be updated.
|
||||
$sql = "UPDATE {assign}
|
||||
SET gradingduedate = duedate + :weeksecs
|
||||
WHERE gradingduedate = 0
|
||||
AND duedate > :timelimit";
|
||||
|
||||
// Calculate the time limit, which is 3 weeks before the current date.
|
||||
$interval = new DateInterval('P3W');
|
||||
$timelimit = new DateTime();
|
||||
$timelimit->sub($interval);
|
||||
|
||||
// Update query params.
|
||||
$params = [
|
||||
'weeksecs' => WEEKSECS,
|
||||
'timelimit' => $timelimit->getTimestamp()
|
||||
];
|
||||
|
||||
// Execute DB update for assign instances.
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Assign savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2017042800, 'assign');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2017061200) {
|
||||
// Data fix any assign group override event priorities which may have been accidentally nulled due to a bug on the group
|
||||
// overrides edit form.
|
||||
|
||||
// First, find all assign group override events having null priority (and join their corresponding assign_overrides entry).
|
||||
$sql = "SELECT e.id AS id, o.sortorder AS priority
|
||||
FROM {assign_overrides} o
|
||||
JOIN {event} e ON (e.modulename = 'assign' AND o.assignid = e.instance AND e.groupid = o.groupid)
|
||||
WHERE o.groupid IS NOT NULL AND e.priority IS NULL
|
||||
ORDER BY o.id";
|
||||
$affectedrs = $DB->get_recordset_sql($sql);
|
||||
|
||||
// Now update the event's priority based on the assign_overrides sortorder we found. This uses similar logic to
|
||||
// assign_refresh_events(), except we've restricted the set of assignments and overrides we're dealing with here.
|
||||
foreach ($affectedrs as $record) {
|
||||
$DB->set_field('event', 'priority', $record->priority, ['id' => $record->id]);
|
||||
}
|
||||
$affectedrs->close();
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2017061200, 'assign');
|
||||
}
|
||||
|
||||
if ($oldversion < 2017061205) {
|
||||
require_once($CFG->dirroot.'/mod/assign/upgradelib.php');
|
||||
$brokenassigns = get_assignments_with_rescaled_null_grades();
|
||||
|
||||
// Set config value.
|
||||
foreach ($brokenassigns as $assign) {
|
||||
set_config('has_rescaled_null_grades_' . $assign, 1, 'assign');
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2017061205, 'assign');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.4.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
// Automatically generated Moodle v3.5.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
@ -3785,71 +3785,6 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$this->assertEquals(1, $completiondata->completionstate);
|
||||
}
|
||||
|
||||
public function get_assignments_with_rescaled_null_grades_provider() {
|
||||
return [
|
||||
'Negative less than one is errant' => [
|
||||
'grade' => -0.64,
|
||||
'count' => 1,
|
||||
],
|
||||
'Negative more than one is errant' => [
|
||||
'grade' => -30.18,
|
||||
'count' => 1,
|
||||
],
|
||||
'Negative one exactly is not errant' => [
|
||||
'grade' => ASSIGN_GRADE_NOT_SET,
|
||||
'count' => 0,
|
||||
],
|
||||
'Positive grade is not errant' => [
|
||||
'grade' => 1,
|
||||
'count' => 0,
|
||||
],
|
||||
'Large grade is not errant' => [
|
||||
'grade' => 100,
|
||||
'count' => 0,
|
||||
],
|
||||
'Zero grade is not errant' => [
|
||||
'grade' => 0,
|
||||
'count' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test determining if the assignment as any null grades that were rescaled.
|
||||
* @dataProvider get_assignments_with_rescaled_null_grades_provider
|
||||
*/
|
||||
public function test_get_assignments_with_rescaled_null_grades($grade, $count) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
$this->setUser($teacher);
|
||||
$assign = $this->create_instance($course, [
|
||||
'grade' => 100,
|
||||
]);
|
||||
|
||||
// Try getting a student's grade. This will give a grade of -1.
|
||||
// Then we can override it with a bad negative grade.
|
||||
$assign->get_user_grade($student->id, true);
|
||||
|
||||
// Set the grade to something errant.
|
||||
$DB->set_field(
|
||||
'assign_grades',
|
||||
'grade',
|
||||
$grade,
|
||||
[
|
||||
'userid' => $student->id,
|
||||
'assignment' => $assign->get_instance()->id,
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertCount($count, get_assignments_with_rescaled_null_grades());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_fix_null_grades
|
||||
* @return array[] Test data for test_fix_null_grades. Each element should contain grade, expectedcount and gradebookvalue
|
||||
|
@ -1,4 +1,10 @@
|
||||
This files describes API changes in the assign code.
|
||||
|
||||
=== 3.9 ===
|
||||
|
||||
* The following functions, previously used (exclusively) by upgrade steps are not available anymore because of the upgrade cleanup performed for this version. See MDL-65809 for more info:
|
||||
- get_assignments_with_rescaled_null_grades()
|
||||
|
||||
=== 3.8 ===
|
||||
* The allow_image_conversion method has been added to the submissionplugins. It determines whether the submission plugin
|
||||
allows image conversion or not. By default conversion is not allowed (except when overwritten in the submission plugin)
|
||||
|
@ -414,27 +414,3 @@ class assign_upgrade_manager {
|
||||
return $newcm;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the assignment as any null grades that were rescaled.
|
||||
*
|
||||
* Null grades are stored as -1 but should never be rescaled.
|
||||
*
|
||||
* @return int[] Array of the ids of all the assignments with rescaled null grades.
|
||||
*/
|
||||
function get_assignments_with_rescaled_null_grades() {
|
||||
global $DB;
|
||||
|
||||
$query = 'SELECT id, assignment FROM {assign_grades}
|
||||
WHERE grade < 0 AND grade <> -1';
|
||||
|
||||
$assignments = array_values($DB->get_records_sql($query));
|
||||
|
||||
$getassignmentid = function ($assignment) {
|
||||
return $assignment->assignment;
|
||||
};
|
||||
|
||||
$assignments = array_map($getassignmentid, $assignments);
|
||||
|
||||
return $assignments;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user