/
upgrade.php
196 lines (155 loc) · 7.65 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
// This file is part of CodeRunner - http://coderunner.org.nz/
//
// CodeRunner is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// CodeRunner is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CodeRunner. If not, see <http://www.gnu.org/licenses/>.
/**
* Upgrade code for the CodeRunner question type.
*
* @param $oldversion the version of this plugin we are upgrading from.
* @return bool success/failure.
*/
defined('MOODLE_INTERNAL') || die();
function xmldb_qtype_coderunner_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2016111105) {
// Define field precheck to be added to question_coderunner_options.
$table = new xmldb_table('question_coderunner_options');
$field = new xmldb_field('precheck', XMLDB_TYPE_INTEGER, '8', null, null, null, '0', 'answerboxlines');
// Conditionally launch add field precheck.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, 2016111105, 'qtype', 'coderunner');
}
if ($oldversion < 2016111200) {
// Define field precheck to be added to question_coderunner_options.
$table = new xmldb_table('question_coderunner_tests');
$field = new xmldb_field('type', XMLDB_TYPE_INTEGER, '8', null, null, null, '0', 'questionid');
// Conditionally launch add field type.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, '2016111200', 'qtype', 'coderunner');
}
if ($oldversion < 2016111201) {
// Rename field type on table question_coderunner_tests to testtype.
$table = new xmldb_table('question_coderunner_tests');
$field = new xmldb_field('type', XMLDB_TYPE_INTEGER, '8', null, null, null, null, 'questionid');
// Launch rename field testtype.
$dbman->rename_field($table, $field, 'testtype');
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, 2016111201, 'qtype', 'coderunner');
}
if ($oldversion < 2016112107) {
// Add fields 'template' and 'iscombinator'. Leave old pertesttemplate
// and combinatortemplate fields in the DB for now, but they're defunct.
$table = new xmldb_table('question_coderunner_options');
$field = new xmldb_field('template', XMLDB_TYPE_TEXT, null, null, null, null, null, 'resultcolumns');
// Conditionally launch add field template.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('iscombinatortemplate', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'template');
// Conditionally launch add field iscombinator.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// For each question that has its own template(s) defined (mostly
// prototypes) copy either the per-test-template or combinator-template
// into the new template field and set iscombinator accordingly.
$sql1 = "UPDATE {question_coderunner_options}
SET template = pertesttemplate, iscombinatortemplate = 0
WHERE enablecombinator = 0
AND grader <> 'CombinatorTemplateGrader'
AND TRIM(COALESCE(pertesttemplate, '')) <> ''";
$DB->execute($sql1);
$sql2 = "UPDATE {question_coderunner_options}
SET template = combinatortemplate, iscombinatortemplate = 1
WHERE (enablecombinator = 1
OR grader = 'CombinatorTemplateGrader')
AND TRIM(COALESCE(combinatortemplate, '')) <> ''";
$DB->execute($sql2);
$sql3 = "UPDATE {question_coderunner_options}
SET grader = 'TemplateGrader'
WHERE grader = 'CombinatorTemplateGrader'";
$DB->execute($sql3);
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, 2016112107, 'qtype', 'coderunner');
}
if ($oldversion < 2016120101) {
// Define field answerpreload to be added to question_coderunner_options.
$table = new xmldb_table('question_coderunner_options');
$field = new xmldb_field('answerpreload', XMLDB_TYPE_TEXT, null, null, null, null, null, 'answerboxcolumns');
// Conditionally launch add field answerpreload.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Drop all the obsolete "show <column>" fields.
$fieldmark = new xmldb_field('showmark');
// Conditionally launch drop field showmark.
if ($dbman->field_exists($table, $fieldmark)) {
$dbman->drop_field($table, $fieldmark);
}
$fieldoutput = new xmldb_field('showoutput');
// Conditionally launch drop field showoutput.
if ($dbman->field_exists($table, $fieldoutput)) {
$dbman->drop_field($table, $fieldoutput);
}
$fieldtest = new xmldb_field('showtest');
// Conditionally launch drop field showtest.
if ($dbman->field_exists($table, $fieldtest)) {
$dbman->drop_field($table, $fieldtest);
}
$fieldstdin = new xmldb_field('showstdin');
// Conditionally launch drop field showstdin.
if ($dbman->field_exists($table, $fieldstdin)) {
$dbman->drop_field($table, $fieldstdin);
}
$fieldexpected = new xmldb_field('showexpected');
// Conditionally launch drop field showstdin.
if ($dbman->field_exists($table, $fieldexpected)) {
$dbman->drop_field($table, $fieldexpected);
}
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, 2016120101, 'qtype', 'coderunner');
}
if ($oldversion < 2016123001) {
// Define field validateonsave to be added to question_coderunner_options.
$table = new xmldb_table('question_coderunner_options');
$field = new xmldb_field('validateonsave', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'answer');
// Conditionally launch add field validateonsave.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, 2016123001, 'qtype', 'coderunner');
}
if ($oldversion < 2017071100) {
// Define field allowmultiplestdins to be added to question_coderunner_options.
$table = new xmldb_table('question_coderunner_options');
$field = new xmldb_field('allowmultiplestdins', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'combinatortemplate');
// Conditionally launch add field allowmultiplestdins.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Coderunner savepoint reached.
upgrade_plugin_savepoint(true, 2017071100, 'qtype', 'coderunner');
}
require_once(__DIR__ . '/upgradelib.php');
update_question_types();
return true;
}