MDL-55956 mod_assign: Set priorities of old assign event overrides
authorJun Pataleta <jun@moodle.com>
Fri, 10 Mar 2017 02:50:07 +0000 (10:50 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 10 Mar 2017 18:04:48 +0000 (18:04 +0000)
mod/assign/db/upgrade.php
mod/assign/version.php

index 9546b56..ee4c961 100644 (file)
@@ -253,5 +253,33 @@ function xmldb_assign_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2017021500, 'assign');
     }
 
+    if ($oldversion < 2017031000) {
+        // Set priority of assign user overrides.
+        $params = [
+            'modulename' => 'assign',
+            'courseid' => 0,
+            'groupid' => 0,
+            'repeatid' => 0
+        ];
+        $DB->set_field('event', 'priority', CALENDAR_EVENT_USER_OVERRIDE_PRIORITY, $params);
+
+        // Set priority for group overrides for existing assign events.
+        $where = 'groupid IS NOT NULL';
+        $assignoverridesrs = $DB->get_recordset_select('assign_overrides', $where, null, '', 'id, assignid, groupid, sortorder');
+        foreach ($assignoverridesrs as $record) {
+            $params = [
+                'modulename' => 'assign',
+                'instance' => $record->assignid,
+                'groupid' => $record->groupid,
+                'repeatid' => 0
+            ];
+            $DB->set_field('event', 'priority', $record->sortorder, $params);
+        }
+        $assignoverridesrs->close();
+
+        // Assign savepoint reached.
+        upgrade_mod_savepoint(true, 2017031000, 'assign');
+    }
+
     return true;
 }
index f920e1f..cb052f3 100644 (file)
@@ -25,6 +25,6 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
-$plugin->version  = 2017021500;    // The current module version (Date: YYYYMMDDXX).
+$plugin->version  = 2017031000;    // The current module version (Date: YYYYMMDDXX).
 $plugin->requires = 2016112900;    // Requires this Moodle version.
 $plugin->cron     = 60;