From 4cd1d4c70f2cafd5a53346cc6fad63373bafc395 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 7 Jun 2017 14:31:51 +0800 Subject: [PATCH] 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. --- lib/db/upgrade.php | 22 ++++++++++++++++++++++ version.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index b130390cf1e..41755e62263 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/version.php b/version.php index e90db3493dd..597192ca5a9 100644 --- a/version.php +++ b/version.php @@ -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.