}
if ($oldversion < 2018072500.00) {
- upgrade_main_savepoint(true, 2018072500.00);
+ // Find all duplicate top level categories per context.
+ $duplicates = $DB->get_records_sql("SELECT qc1.*
+ FROM {question_categories} qc1
+ JOIN {question_categories} qc2
+ ON qc1.contextid = qc2.contextid AND qc1.id <> qc2.id
+ WHERE qc1.parent = 0 AND qc2.parent = 0
+ ORDER BY qc1.contextid, qc1.id");
+
+ // For each context, let the first top category to remain as top category and make the rest its children.
+ $currentcontextid = 0;
+ $chosentopid = 0;
+ foreach ($duplicates as $duplicate) {
+ if ($currentcontextid != $duplicate->contextid) {
+ $currentcontextid = $duplicate->contextid;
+ $chosentopid = $duplicate->id;
+ } else {
+ $DB->set_field('question_categories', 'parent', $chosentopid, ['id' => $duplicate->id]);
+ }
+ }
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2018072500.00);
+ }
+
++ if ($oldversion < 2018073000.00) {
+ // Main savepoint reached.
+ if (!file_exists($CFG->dirroot . '/admin/tool/assignmentupgrade/version.php')) {
+ unset_all_config_for_plugin('tool_assignmentupgrade');
+ }
++ upgrade_main_savepoint(true, 2018073000.00);
+ }
+
return true;
}
defined('MOODLE_INTERNAL') || die();
- $version = 2018072700.00; // YYYYMMDD = weekly release date of this DEV branch.
-$version = 2018072500.00; // YYYYMMDD = weekly release date of this DEV branch.
++$version = 2018073000.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.