weekly release 2.2dev
[moodle.git] / question / type / multianswer / db / upgrade.php
CommitLineData
aeb15530 1<?php
d3603157 2// This file is part of Moodle - http://moodle.org/
dfdd5332 3//
d3603157
TH
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
dfdd5332 8//
d3603157
TH
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
dfdd5332 13//
d3603157
TH
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Multi-answer question type upgrade code.
19 *
20 * @package qtype
21 * @subpackage multianswer
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
dfdd5332 26
a17b297d
TH
27defined('MOODLE_INTERNAL') || die();
28
29
d3603157
TH
30/**
31 * Upgrade code for the multi-answer question type.
32 * @param int $oldversion the version we are upgrading from.
33 */
775f811a 34function xmldb_qtype_multianswer_upgrade($oldversion) {
35 global $CFG, $DB;
dfdd5332 36
775f811a 37 $dbman = $DB->get_manager();
dfdd5332 38
a4cdd6d2
PS
39 if ($oldversion < 2008050800) {
40 //hey - no functions here in this file !!!!!!!
e2134c5d 41
a4cdd6d2
PS
42 $rs = $DB->get_recordset_sql("SELECT q.id, q.category, qma.sequence
43 FROM {question} q
44 JOIN {question_multianswer} qma ON q.id = qma.question");
bae73624 45 foreach ($rs as $q) {
ed5ba2df 46 if (!empty($q->sequence)) {
a4cdd6d2
PS
47 $DB->execute("UPDATE {question}
48 SET parent = ?, category = ?
49 WHERE id IN ($q->sequence) AND parent <> 0",
50 array($q->id, $q->category));
ed5ba2df 51 }
e2134c5d 52 }
bae73624 53 $rs->close();
a4cdd6d2
PS
54
55 /// multianswer savepoint reached
56 upgrade_plugin_savepoint(true, 2008050800, 'qtype', 'multianswer');
e2134c5d 57 }
aeb15530 58
a4cdd6d2
PS
59 return true;
60}