Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-41092

Assignment cron mail function - submissions SQL incorrect

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.5.3
    • Component/s: Assignment
    • Labels:

      Description

      When the cron function under assingments is run , the SQL used to get the submissions for each course is incorrect. The SQL starts by selecting the course column from the assign table which is a foreign key ( to course table). Hence , the get_records_sql() method outputs this error whenever it finds more than one course linked to an assignment ( which is a perfectly normal case ):

      Error

       Did you remember to make the first column something unique in your call to get_records? Duplicate value 'xxxxxx' found in column 'course'.* line 1014 of /lib/dml/mysqli_native_moodle_database.php: call to debugging()
      * line 1493 of /mod/assign/locallib.php: call to mysqli_native_moodle_database->get_records_sql()
      * line 859 of /mod/assign/lib.php: call to assign::cron()
      * line 267 of /lib/cronlib.php: call to assign_cron()
      * line 61 of /admin/cli/cron.php: call to cron_run()
      

      Code in Moodle 2.5 looks like this :

      /mod/assign/locallib.php

      	        $sql = 'SELECT a.course, a.name, a.blindmarking, a.revealidentities,
      	                       g.*, g.id as gradeid, g.timemodified as lastmodified
      	                 FROM {assign} a
      	                 JOIN {assign_grades} g ON g.assignment = a.id
      	                 LEFT JOIN {assign_user_flags} uf ON uf.assignment = a.id AND uf.userid = g.userid
      	                WHERE g.timemodified >= :yesterday AND
      	                      g.timemodified <= :today AND
      	                      uf.mailed = 0';
      

      In my understanding,SQL used in Moodle 2.2.6 took care of that by calling on the submissions table first like this:

      /mod/assignment/lib.php

      function assignment_get_unmailed_submissions($starttime, $endtime) {
      	    global $CFG, $DB;
      	
      	    return $DB->get_records_sql("SELECT s.*, a.course, a.name
      	                                   FROM {assignment_submissions} s,
      	                                        {assignment} a
      	                                  WHERE s.mailed = 0
      	                                        AND s.timemarked <= ?
      	                                        AND s.timemarked >= ?
      	                                        AND s.assignment = a.id", array($endtime, $starttime));
      }
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  1 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    11/Nov/13