Skip to content
Browse files

MDL-31987 Assignment module: fix sql for postgres.

  • Loading branch information...
1 parent b8ba23c commit 74fc24a9160ef0a8df24ca13f242b42cf8dc8e05 @danpoltawski danpoltawski committed with rwijaya Jul 2, 2012
Showing with 15 additions and 15 deletions.
  1. +15 −15 mod/assignment/db/upgrade.php
View
30 mod/assignment/db/upgrade.php
@@ -35,24 +35,24 @@ function xmldb_assignment_upgrade($oldversion) {
if ($oldversion < 2012062800) {
// Fixed/updated numfiles field in assignment_submissions table to count the actual
- // number of files has been uploaded.
+ // number of files has been uploaded when sendformarking is disabled
upgrade_set_timeout(600); // increase excution time for in large sites
$fs = get_file_storage();
- $selectcount = 'SELECT COUNT(s.id), cm.id AS cmid';
- $select = 'SELECT s.id, cm.id AS cmid';
- $query = " FROM {assignment_submissions} s
- INNER JOIN {course_modules} cm
- ON s.assignment = cm.instance
- JOIN {assignment} a
- ON a.id = s.assignment
- WHERE a.assignmenttype in ('upload', 'uploadsingle') AND
- cm.module = (SELECT id
- FROM {modules}
- WHERE name = 'assignment')";
-
- $countsubmissions = $DB->count_records_sql($selectcount. $query);
- $submissions = $DB->get_recordset_sql($select. $query);
+ // Fetch the moduleid for use in the course_modules table
+ $moduleid = $DB->get_field('modules', 'id', array('name' => 'assignment'), MUST_EXIST);
+
+ $selectcount = 'SELECT COUNT(s.id) ';
+ $select = 'SELECT s.id, cm.id AS cmid ';
+ $query = 'FROM {assignment_submissions} s
+ JOIN {assignment} a ON a.id = s.assignment
+ JOIN {course_modules} cm ON a.id = cm.instance AND cm.module = :moduleid
+ WHERE assignmenttype = :assignmenttype';
+
+ $params = array('moduleid' => $moduleid, 'assignmenttype' => 'upload');
+
+ $countsubmissions = $DB->count_records_sql($selectcount.$query, $params);
+ $submissions = $DB->get_recordset_sql($select.$query, $params);
$pbar = new progress_bar('assignmentupgradenumfiles', 500, true);
$i = 0;

0 comments on commit 74fc24a

Please sign in to comment.
Something went wrong with that request. Please try again.