MDL-59042 upgrade: datafix assign group overrides with null priority

Find any events records for assign group overrides having null priority
and sets their priority to the sortorder value from the corresponding
assign_overrides table entry.
This commit is contained in:
Jake Dallimore 2017-06-07 14:31:51 +08:00
parent 67ed6d415e
commit 4cd1d4c70f
2 changed files with 23 additions and 1 deletions

View File

@ -2864,6 +2864,28 @@ function xmldb_main_upgrade($oldversion) {
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2017060800.01) {
// Data fix any assign group override event priorities which may have been accidentally nulled due to a bug on the group
// overrides edit form.
// First, find all assign group override events having null priority (and join their corresponding assign_overrides entry).
$sql = "SELECT e.id AS id, o.sortorder AS priority
FROM {assign_overrides} o
JOIN {event} e ON (e.modulename = 'assign' AND o.assignid = e.instance AND e.groupid = o.groupid)
WHERE o.groupid IS NOT NULL AND e.priority IS NULL
ORDER BY o.id";
$affectedrs = $DB->get_recordset_sql($sql);
// Now update the event's priority based on the assign_overrides sortorder we found. This uses similar logic to
// assign_refresh_events(), except we've restricted the set of assignments and overrides we're dealing with here.
foreach ($affectedrs as $record) {
$DB->set_field('event', 'priority', $record->priority, ['id' => $record->id]);
}
$affectedrs->close();
// Main savepoint reached.
upgrade_main_savepoint(true, 2017060800.01);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017060800.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017060800.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.