MDL-31987 Assignment module: fix sql for postgres.
authorDan Poltawski <talktodan@gmail.com>
Thu, 28 Jun 2012 06:35:37 +0000 (14:35 +0800)
committerRossiani Wijaya <rwijaya@moodle.com>
Mon, 2 Jul 2012 06:49:29 +0000 (14:49 +0800)
mod/assignment/db/upgrade.php

index 256bda9..3f87985 100644 (file)
@@ -34,24 +34,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;