3 // This file keeps track of upgrades to
4 // the multianswer qtype plugin
6 // Sometimes, changes between versions involve
7 // alterations to database structures and other
8 // major things that may break installations.
10 // The upgrade function in this file will attempt
11 // to perform all the necessary actions to upgrade
12 // your older installtion to the current version.
14 // If there's something it cannot do itself, it
15 // will tell you what you need to do.
17 // The commands in here will all be database-neutral,
18 // using the functions defined in lib/ddllib.php
20 function xmldb_qtype_multianswer_upgrade($oldversion=0) {
22 global $CFG, $THEME, $db;
26 /// And upgrade begins here. For each one, you'll need one
27 /// block of code similar to the next one. Please, delete
28 /// this comment lines once this file start handling proper
31 /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
32 /// $result = result of "/lib/ddllib.php" function calls
35 if ($result && $oldversion < 2008050800) {
36 question_multianswer_fix_subquestion_parents_and_categories();
43 * Due to MDL-14750, subquestions of multianswer questions restored from backup will
44 * have the wrong parent, and due to MDL-10899 subquestions of multianswer questions
45 * that have been moved between categories will be in the wrong category, This code fixes these up.
47 function question_multianswer_fix_subquestion_parents_and_categories() {
51 $rs = get_recordset_sql('SELECT q.id, q.category, qma.sequence FROM ' . $CFG->prefix
.
52 'question q JOIN ' . $CFG->prefix
. 'question_multianswer qma ON q.id = qma.question');
54 while ($q = rs_fetch_next_record($rs)) {
55 if (!empty($q->sequence
)) {
56 $result = $result && execute_sql('UPDATE ' . $CFG->prefix
. 'question' .
57 ' SET parent = ' . $q->id
. ', category = ' . $q->category
.
58 ' WHERE id IN (' . $q->sequence
. ') AND parent <> 0');