Updated the HEAD build version to 20080816
[moodle.git] / question / type / multianswer / db / upgrade.php
CommitLineData
1061756d 1<?php // $Id$
dfdd5332 2
3// This file keeps track of upgrades to
4// the multianswer qtype plugin
5//
6// Sometimes, changes between versions involve
7// alterations to database structures and other
8// major things that may break installations.
9//
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.
13//
14// If there's something it cannot do itself, it
15// will tell you what you need to do.
16//
17// The commands in here will all be database-neutral,
b1f93b15 18// using the methods of database_manager class
dfdd5332 19
20function xmldb_qtype_multianswer_upgrade($oldversion=0) {
21
219f652b 22 global $CFG, $THEME, $DB;
dfdd5332 23
24 $result = true;
25
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
29/// upgrade code.
30
31/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
b1f93b15 32/// $result = result of database_manager methods
dfdd5332 33/// }
34
e2134c5d 35 if ($result && $oldversion < 2008050800) {
36 question_multianswer_fix_subquestion_parents_and_categories();
37 }
38
dfdd5332 39 return $result;
40}
41
e2134c5d 42/**
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.
46 */
47function question_multianswer_fix_subquestion_parents_and_categories() {
bae73624 48 global $CFG, $DB;
e2134c5d 49
50 $result = true;
bae73624 51 $rs = $DB->get_recordset_sql('SELECT q.id, q.category, qma.sequence
52 FROM {question} q JOIN {question_multianswer} qma ON q.id = qma.question');
e2134c5d 53 if ($rs) {
bae73624 54 foreach ($rs as $q) {
ed5ba2df 55 if (!empty($q->sequence)) {
bae73624 56 $result = $result && $DB->execute("UPDATE {question}
57 SET parent = ?, category = ?
58 WHERE id IN ($q->sequence) AND parent <> 0",
59 array($q->id, $q->category));
ed5ba2df 60 }
e2134c5d 61 }
bae73624 62 $rs->close();
e2134c5d 63 } else {
64 $result = false;
65 }
66 return $result;
67}
dfdd5332 68?>