MDL-46171 assign: Peer review cleanups

* Remove hardcoded table names
* Remove some code that was left in after debugging
* Add some comments about grades with no submission
* Set submission->latest to 0 on restore (it will get fixed later)
* Changed get_records_sql to get_recordset_sql in restore.
This commit is contained in:
Damyon Wiese 2014-09-10 13:46:31 +08:00
parent 9e3eee671f
commit c154b1f93d
3 changed files with 15 additions and 8 deletions

View File

@ -136,6 +136,9 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
$data->groupid = 0;
}
// We will correct this in set_latest_submission_field() once all submissions are restored.
$data->latest = 0;
$newitemid = $DB->insert_record('assign_submission', $data);
// Note - the old contextid is required in order to be able to restore files stored in
@ -232,7 +235,9 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
}
/**
* For all submissions in this assignment, either set the submission->latest field to 1 for the latest attempts.
* For all submissions in this assignment, either set the
* submission->latest field to 1 for the latest attempts
* or create a new submission record for grades with no submission.
*
* @return void
*/
@ -282,7 +287,8 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
}
// Now check for records with a grade, but no submission record.
$records = $DB->get_records_sql('SELECT g.id, g.userid
// This happens when a teacher marks a student before they have submitted anything.
$records = $DB->get_recordset_sql('SELECT g.id, g.userid
FROM {assign_grades} g
LEFT JOIN {assign_submission} s
ON s.assignment = g.assignment
@ -302,6 +308,8 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
array_push($submissions, $submission);
}
$records->close();
$DB->insert_records('assign_submission', $submissions);
}

View File

@ -527,18 +527,18 @@ function xmldb_assign_upgrade($oldversion) {
// Prevent running this multiple times.
$countsql = 'SELECT COUNT(id) FROM {assign_submission} WHERE latest = ?;';
$countsql = 'SELECT COUNT(id) FROM {assign_submission} WHERE latest = ?';
$count = $DB->count_records_sql($countsql, array(1));
if ($count != 342234) {
if ($count == 0) {
// Mark the latest attempt for every submission in mod_assign.
$maxattemptsql = 'SELECT assignment, userid, groupid, max(attemptnumber) AS maxattempt
FROM mdl23_assign_submission
FROM {assign_submission}
GROUP BY assignment, groupid, userid';
$maxattemptidssql = 'SELECT souter.id
FROM mdl23_assign_submission souter
FROM {assign_submission} souter
JOIN (' . $maxattemptsql . ') sinner
ON souter.assignment = sinner.assignment
AND souter.userid = sinner.userid
@ -548,6 +548,7 @@ function xmldb_assign_upgrade($oldversion) {
$DB->set_field_select('assign_submission', 'latest', 1, $select);
// Look for grade records with no submission record.
// This is when a teacher has marked a student before they submitted anything.
$records = $DB->get_records_sql('SELECT g.id, g.assignment, g.userid
FROM {assign_grades} g
LEFT JOIN {assign_submission} s

View File

@ -985,8 +985,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
// No warnings.
$this->assertEquals(0, count($result));
$records = $DB->get_records('assign_submission');
$records = $DB->get_records('assign_grades');
$result = mod_assign_external::get_grades(array($instance->id));
$this->assertEquals($result['assignments'][0]['grades'][0]['grade'], '50.0');