Skip to content

Commit

Permalink
MDL-46171 assign: Peer review cleanups
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Damyon Wiese committed Sep 24, 2014
1 parent 9e3eee6 commit c154b1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 10 additions & 2 deletions mod/assign/backup/moodle2/restore_assign_stepslib.php
Expand Up @@ -136,6 +136,9 @@ protected function process_assign_submission($data) {
$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
Expand Down Expand Up @@ -232,7 +235,9 @@ protected function process_assign_plugin_config($data) {
}

/**
* 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
*/
Expand Down Expand Up @@ -282,7 +287,8 @@ protected function set_latest_submission_field() {
}

// 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
Expand All @@ -302,6 +308,8 @@ protected function set_latest_submission_field() {
array_push($submissions, $submission);
}

$records->close();

$DB->insert_records('assign_submission', $submissions);
}

Expand Down
9 changes: 5 additions & 4 deletions mod/assign/db/upgrade.php
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions mod/assign/tests/externallib_test.php
Expand Up @@ -985,8 +985,6 @@ public function test_save_grade() {
// 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');
Expand Down

0 comments on commit c154b1f

Please sign in to comment.