From c154b1f93d97363f9aa0492bdebe832f089cbb32 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 10 Sep 2014 13:46:31 +0800 Subject: [PATCH] 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. --- mod/assign/backup/moodle2/restore_assign_stepslib.php | 12 ++++++++++-- mod/assign/db/upgrade.php | 9 +++++---- mod/assign/tests/externallib_test.php | 2 -- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/mod/assign/backup/moodle2/restore_assign_stepslib.php b/mod/assign/backup/moodle2/restore_assign_stepslib.php index db0f0990a2c..b603b49e6db 100644 --- a/mod/assign/backup/moodle2/restore_assign_stepslib.php +++ b/mod/assign/backup/moodle2/restore_assign_stepslib.php @@ -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); } diff --git a/mod/assign/db/upgrade.php b/mod/assign/db/upgrade.php index 2a6bd17264e..63f5b27a070 100755 --- a/mod/assign/db/upgrade.php +++ b/mod/assign/db/upgrade.php @@ -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 diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index 9b33ebe0fe1..ceb7f0d0915 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -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'); -- 2.11.4.GIT