mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-70480 mod_assign: fix user and group submission and update database
This commit is contained in:
parent
4ce642e8ba
commit
a0508fbb2b
@ -93,5 +93,42 @@ function xmldb_assign_upgrade($oldversion) {
|
||||
// Automatically generated Moodle v4.0.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2022071300) {
|
||||
// The most recent assign submission should always have latest = 1, we want to find all records where this is not the case.
|
||||
// Find the records with the maximum timecreated for each assign and user combination where latest is also 0.
|
||||
$sqluser = "SELECT s.id
|
||||
FROM {assign_submission} s
|
||||
WHERE s.timecreated = (
|
||||
SELECT MAX(timecreated) timecreated
|
||||
FROM {assign_submission} sm
|
||||
WHERE s.assignment = sm.assignment
|
||||
AND s.userid = sm.userid
|
||||
AND sm.groupid = 0)
|
||||
AND s.groupid = 0
|
||||
AND s.latest = 0";
|
||||
$idstofixuser = $DB->get_records_sql($sqluser, null);
|
||||
|
||||
$sqlgroup = "SELECT s.id
|
||||
FROM {assign_submission} s
|
||||
WHERE s.timecreated = (
|
||||
SELECT MAX(timecreated) timecreated
|
||||
FROM {assign_submission} sm
|
||||
WHERE s.assignment = sm.assignment
|
||||
AND s.groupid = sm.groupid
|
||||
AND sm.groupid <> 0)
|
||||
AND s.groupid <> 0
|
||||
AND s.latest = 0";
|
||||
$idstofixgroup = $DB->get_records_sql($sqlgroup, null);
|
||||
|
||||
$idstofix = array_merge(array_keys($idstofixuser), array_keys($idstofixgroup));
|
||||
|
||||
if (count($idstofix)) {
|
||||
[$insql, $inparams] = $DB->get_in_or_equal($idstofix);
|
||||
$DB->set_field_select('assign_submission', 'latest', 1, "id $insql", $inparams);
|
||||
}
|
||||
|
||||
// Assignment savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2022071300, 'assign');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -3168,12 +3168,14 @@ class assign {
|
||||
$submission->latest = 1;
|
||||
}
|
||||
}
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
if ($submission->latest) {
|
||||
// This is the case when we need to set latest to 0 for all the other attempts.
|
||||
$DB->set_field('assign_submission', 'latest', 0, $params);
|
||||
}
|
||||
$submission->status = ASSIGN_SUBMISSION_STATUS_NEW;
|
||||
$sid = $DB->insert_record('assign_submission', $submission);
|
||||
$transaction->allow_commit();
|
||||
return $DB->get_record('assign_submission', array('id' => $sid));
|
||||
}
|
||||
return false;
|
||||
@ -3950,11 +3952,13 @@ class assign {
|
||||
$submission->latest = 1;
|
||||
}
|
||||
}
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
if ($submission->latest) {
|
||||
// This is the case when we need to set latest to 0 for all the other attempts.
|
||||
$DB->set_field('assign_submission', 'latest', 0, $params);
|
||||
}
|
||||
$sid = $DB->insert_record('assign_submission', $submission);
|
||||
$transaction->allow_commit();
|
||||
return $DB->get_record('assign_submission', array('id' => $sid));
|
||||
}
|
||||
return false;
|
||||
|
@ -25,5 +25,5 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->version = 2022041900; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2022071300; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2022041200; // Requires this Moodle version.
|
||||
|
Loading…
x
Reference in New Issue
Block a user