MDL-61132 Questions: Upgrade step to add Top to existing contexts

Upgrade script to add a "Top" category as a real category to the question bank
This commit is contained in:
Shamim Rezaie
2018-02-05 11:20:50 +11:00
parent a409707794
commit d2c4ff10bf
2 changed files with 40 additions and 2 deletions
+38
View File
@@ -1935,5 +1935,43 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017122200.01);
}
if ($oldversion < 2018020500.00) {
$topcategory = new stdClass();
$topcategory->name = 'top'; // A non-real name for the top category. It will be localised at the display time.
$topcategory->info = '';
$topcategory->parent = 0;
$topcategory->sortorder = 0;
// Get the total record count - used for the progress bar.
$total = $DB->count_records_sql("SELECT COUNT(DISTINCT contextid) FROM {question_categories} WHERE parent = 0");
// Get the records themselves - a list of contextids.
$rs = $DB->get_recordset_sql("SELECT DISTINCT contextid FROM {question_categories} WHERE parent = 0");
// For each context, create a single top-level category.
$i = 0;
$pbar = new progress_bar('createtopquestioncategories', 500, true);
foreach ($rs as $contextid => $notused) {
$topcategory->contextid = $contextid;
$topcategory->stamp = make_unique_id_code();
$topcategoryid = $DB->insert_record('question_categories', $topcategory);
$DB->set_field_select('question_categories', 'parent', $topcategoryid,
'contextid = ? AND id <> ? AND parent = 0',
array($contextid, $topcategoryid));
// Update progress.
$i++;
$pbar->update($i, $total, "Creating top-level question categories - $i/$total.");
}
$rs->close();
// Main savepoint reached.
upgrade_main_savepoint(true, 2018020500.00);
}
return true;
}
+2 -2
View File
@@ -29,11 +29,11 @@
defined('MOODLE_INTERNAL') || die();
$version = 2018020100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2018020500.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.5dev (Build: 20180201)'; // Human-friendly version name
$release = '3.5dev (Build: 20180205)'; // Human-friendly version name
$branch = '35'; // This version's branch.
$maturity = MATURITY_ALPHA; // This version's maturity level.