Permalink
Browse files

Merge branch 'MDL-52501' of https://github.com/NeillM/moodle

  • Loading branch information...
dmonllao committed Jul 10, 2017
2 parents bf51478 + 733c497 commit 0245f733b783d84367f18d0149d61c3a2be47462
Showing with 51 additions and 49 deletions.
  1. +28 −26 mod/assign/backup/moodle2/restore_assign_stepslib.php
  2. +23 −23 mod/assign/db/upgrade.php
@@ -282,6 +282,34 @@ protected function set_latest_submission_field() {
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assignmentid = $this->get_new_parentid('assign');
// First check for records with a grade, but no submission record.
// This happens when a teacher marks a student before they have submitted anything.
$records = $DB->get_recordset_sql('SELECT g.id, g.userid, g.attemptnumber
FROM {assign_grades} g
LEFT JOIN {assign_submission} s
ON s.assignment = g.assignment
AND s.userid = g.userid
WHERE s.id IS NULL AND g.assignment = ?', array($assignmentid));
$submissions = array();
foreach ($records as $record) {
$submission = new stdClass();
$submission->assignment = $assignmentid;
$submission->userid = $record->userid;
$submission->attemptnumber = $record->attemptnumber;
$submission->status = ASSIGN_SUBMISSION_STATUS_NEW;
$submission->groupid = 0;
$submission->latest = 0;
$submission->timecreated = time();
$submission->timemodified = time();
array_push($submissions, $submission);
}
$records->close();
$DB->insert_records('assign_submission', $submissions);
// This code could be rewritten as a monster SQL - but the point of adding this "latest" field
// to the submissions table in the first place was to get away from those hard to maintain SQL queries.
@@ -319,32 +347,6 @@ protected function set_latest_submission_field() {
$DB->update_record('assign_submission', $submission);
}
}
// Now check for records with a grade, but no submission record.
// 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
AND s.userid = g.userid
WHERE s.id IS NULL AND g.assignment = ?', array($assignmentid));
$submissions = array();
foreach ($records as $record) {
$submission = new stdClass();
$submission->assignment = $assignmentid;
$submission->userid = $record->userid;
$submission->status = ASSIGN_SUBMISSION_STATUS_NEW;
$submission->groupid = 0;
$submission->latest = 1;
$submission->timecreated = time();
$submission->timemodified = time();
array_push($submissions, $submission);
}
$records->close();
$DB->insert_records('assign_submission', $submissions);
}
/**
@@ -79,6 +79,29 @@ function xmldb_assign_upgrade($oldversion) {
$count = $DB->count_records_sql($countsql, array(1));
if ($count == 0) {
// 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, g.attemptnumber
FROM {assign_grades} g
LEFT JOIN {assign_submission} s
ON s.assignment = g.assignment
AND s.userid = g.userid
WHERE s.id IS NULL');
$submissions = array();
foreach ($records as $record) {
$submission = new stdClass();
$submission->assignment = $record->assignment;
$submission->userid = $record->userid;
$submission->attemptnumber = $record->attemptnumber;
$submission->status = 'new';
$submission->groupid = 0;
$submission->latest = 0;
$submission->timecreated = time();
$submission->timemodified = time();
array_push($submissions, $submission);
}
$DB->insert_records('assign_submission', $submissions);
// Mark the latest attempt for every submission in mod_assign.
$maxattemptsql = 'SELECT assignment, userid, groupid, max(attemptnumber) AS maxattempt
@@ -105,29 +128,6 @@ function xmldb_assign_upgrade($oldversion) {
$select = 'id IN(' . $maxattemptidssql . ')';
$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
ON s.assignment = g.assignment
AND s.userid = g.userid
WHERE s.id IS NULL');
$submissions = array();
foreach ($records as $record) {
$submission = new stdClass();
$submission->assignment = $record->assignment;
$submission->userid = $record->userid;
$submission->status = 'new';
$submission->groupid = 0;
$submission->latest = 1;
$submission->timecreated = time();
$submission->timemodified = time();
array_push($submissions, $submission);
}
$DB->insert_records('assign_submission', $submissions);
}
// Assign savepoint reached.

0 comments on commit 0245f73

Please sign in to comment.