MDL-62897 Questions: Find duplicate top cats per context and fix them
This commit is contained in:
@@ -2268,5 +2268,30 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2018062800.03);
|
||||
}
|
||||
|
||||
if ($oldversion < 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);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2018072000.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2018072500.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user