MDL-6535 new features for the essay qtype. Part I DB tables and editing form.
[moodle.git] / question / type / essay / db / upgrade.php
CommitLineData
894e8b4e
TH
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Essay question type upgrade code.
20 *
21 * @package qtype
22 * @subpackage essay
23 * @copyright 2011 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27
28defined('MOODLE_INTERNAL') || die();
29
30
31/**
32 * Upgrade code for the essay question type.
33 * @param int $oldversion the version we are upgrading from.
34 */
35function xmldb_qtype_essay_upgrade($oldversion) {
36 global $CFG, $DB;
37
38 $dbman = $DB->get_manager();
39
40 if ($oldversion < 2011031000) {
41 // Define table qtype_essay_options to be created
42 $table = new xmldb_table('qtype_essay_options');
43
44 // Adding fields to table qtype_essay_options
45 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
46 $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
47 $table->add_field('responseformat', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, 'editor');
48 $table->add_field('responsefieldlines', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '15');
49 $table->add_field('attachments', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
50 $table->add_field('graderinfo', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
51 $table->add_field('graderinfoformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
52
53 // Adding keys to table qtype_essay_options
54 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
55 $table->add_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id'));
56
57 // Conditionally launch create table for qtype_essay_options
58 if (!$dbman->table_exists($table)) {
59 $dbman->create_table($table);
60 }
61
62 // essay savepoint reached
63 upgrade_plugin_savepoint(true, 2011031000, 'qtype', 'essay');
64 }
65
66 if ($oldversion < 2011031000) {
67 // Insert a row into the qtype_essay_options table for each existing essay question.
68 $DB->execute("
69 INSERT INTO {qtype_essay_options} (questionid, responseformat,
70 responsefieldlines, attachments, graderinfo, graderinfoformat)
71 SELECT id, 'editor', 15, 0, '', " . FORMAT_MOODLE . "
72 FROM {question}
73 WHERE qtype = 'essay'");
74 }
75
76 return true;
77}