MDL-20636 Fix a bunch of minor errors in the truefalse preview.
[moodle.git] / mod / quiz / report / statistics / db / upgrade.php
CommitLineData
aeb15530 1<?php
9859e26c 2
2ece30dd 3function xmldb_quiz_statistics_upgrade($oldversion) {
9859e26c 4
5 global $DB;
b0ec60f1 6
9859e26c 7 $dbman = $DB->get_manager();
8
9859e26c 9//===== 1.9.0 upgrade line ======//
10
a4cdd6d2 11 if ($oldversion < 2008072401) {
9859e26c 12 //register cron to run every 5 hours.
a4cdd6d2 13 $DB->set_field('quiz_report', 'cron', HOURSECS*5, array('name'=>'statistics'));
b0ec60f1 14
15 /// statistics savepoint reached
a4cdd6d2 16 upgrade_plugin_savepoint(true, 2008072401, 'quizreport', 'statistics');
9859e26c 17 }
b0ec60f1 18
a4cdd6d2 19 if ($oldversion < 2008072500) {
162f9635 20
21 /// Define field s to be added to quiz_question_statistics
22 $table = new xmldb_table('quiz_question_statistics');
2a88f626 23 $field = new xmldb_field('s', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'subquestion');
162f9635 24
25 /// Conditionally launch add field s
26 if (!$dbman->field_exists($table, $field)) {
27 $dbman->add_field($table, $field);
28 }
29
b0ec60f1 30 /// statistics savepoint reached
a4cdd6d2 31 upgrade_plugin_savepoint(true, 2008072500, 'quizreport', 'statistics');
162f9635 32 }
b0ec60f1 33
a4cdd6d2 34 if ($oldversion < 2008072800) {
43ec99aa 35
36 /// Define field maxgrade to be added to quiz_question_statistics
37 $table = new xmldb_table('quiz_question_statistics');
2a88f626 38 $field = new xmldb_field('maxgrade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'subquestions');
43ec99aa 39
40 /// Conditionally launch add field maxgrade
41 if (!$dbman->field_exists($table, $field)) {
42 $dbman->add_field($table, $field);
43 }
44
b0ec60f1 45 /// statistics savepoint reached
a4cdd6d2 46 upgrade_plugin_savepoint(true, 2008072800, 'quizreport', 'statistics');
43ec99aa 47 }
48
a4cdd6d2 49 if ($oldversion < 2008072801) {
43ec99aa 50
51 /// Define field positions to be added to quiz_question_statistics
52 $table = new xmldb_table('quiz_question_statistics');
2a88f626 53 $field = new xmldb_field('positions', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'maxgrade');
43ec99aa 54
55 /// Conditionally launch add field positions
56 if (!$dbman->field_exists($table, $field)) {
57 $dbman->add_field($table, $field);
58 }
59
b0ec60f1 60 /// statistics savepoint reached
a4cdd6d2 61 upgrade_plugin_savepoint(true, 2008072801, 'quizreport', 'statistics');
43ec99aa 62 }
f9a2cf86 63
a4cdd6d2 64 if ($oldversion < 2008081500) {
f9a2cf86 65 /// Changing type of field maxgrade on table quiz_question_statistics to number
66 $table = new xmldb_table('quiz_question_statistics');
2a88f626 67 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'subquestions');
f9a2cf86 68
69 /// Launch change of type for field maxgrade
70 $dbman->change_field_type($table, $field);
b0ec60f1 71
72 /// statistics savepoint reached
a4cdd6d2 73 upgrade_plugin_savepoint(true, 2008081500, 'quizreport', 'statistics');
f9a2cf86 74 }
75
a4cdd6d2 76 if ($oldversion < 2008082600) {
869309b8 77
78 /// Define table quiz_question_response_stats to be created
79 $table = new xmldb_table('quiz_question_response_stats');
80
81 /// Adding fields to table quiz_question_response_stats
2a88f626 82 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
83 $table->add_field('quizstatisticsid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
84 $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
85 $table->add_field('anssubqid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
86 $table->add_field('response', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
87 $table->add_field('rcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
cce1b655 88 $table->add_field('credit', XMLDB_TYPE_NUMBER, '15, 5', null, XMLDB_NOTNULL, null, null);
869309b8 89
90 /// Adding keys to table quiz_question_response_stats
91 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
92
93 /// Conditionally launch create table for quiz_question_response_stats
94 if (!$dbman->table_exists($table)) {
95 $dbman->create_table($table);
96 }
97
b0ec60f1 98 /// statistics savepoint reached
a4cdd6d2 99 upgrade_plugin_savepoint(true, 2008082600, 'quizreport', 'statistics');
869309b8 100 }
b0ec60f1 101
a4cdd6d2 102 if ($oldversion < 2008090500) {
869309b8 103 //delete all cached results first
a4cdd6d2
PS
104 $DB->delete_records('quiz_statistics');
105 $DB->delete_records('quiz_question_statistics');
106 $DB->delete_records('quiz_question_response_stats');
869309b8 107 /// Define field anssubqid to be dropped from quiz_question_response_stats
a4cdd6d2
PS
108 $table = new xmldb_table('quiz_question_response_stats');
109 $field = new xmldb_field('anssubqid');
b0ec60f1 110
869309b8 111 /// Conditionally launch drop field subqid
a4cdd6d2
PS
112 if ($dbman->field_exists($table, $field)) {
113 $dbman->drop_field($table, $field);
114 }
b0ec60f1 115
869309b8 116 /// Define field subqid to be added to quiz_question_response_stats
a4cdd6d2 117 $field = new xmldb_field('subqid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'questionid');
b0ec60f1 118
869309b8 119 /// Conditionally launch add field subqid
a4cdd6d2
PS
120 if (!$dbman->field_exists($table, $field)) {
121 $dbman->add_field($table, $field);
122 }
b0ec60f1 123
869309b8 124 /// Define field aid to be added to quiz_question_response_stats
a4cdd6d2 125 $field = new xmldb_field('aid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'subqid');
b0ec60f1 126
869309b8 127 /// Conditionally launch add field aid
a4cdd6d2
PS
128 if (!$dbman->field_exists($table, $field)) {
129 $dbman->add_field($table, $field);
869309b8 130 }
b0ec60f1 131
132 /// statistics savepoint reached
a4cdd6d2 133 upgrade_plugin_savepoint(true, 2008090500, 'quizreport', 'statistics');
869309b8 134 }
b0ec60f1 135
a4cdd6d2 136 if ($oldversion < 2008111000) {
74686047 137 //delete all cached results first
a4cdd6d2
PS
138 $DB->delete_records('quiz_statistics');
139 $DB->delete_records('quiz_question_statistics');
140 $DB->delete_records('quiz_question_response_stats');
141
74686047 142 /// Define field anssubqid to be dropped from quiz_question_response_stats
a4cdd6d2 143 $table = new xmldb_table('quiz_question_statistics');
74686047 144 /// Define field subqid to be added to quiz_question_response_stats
a4cdd6d2 145 $field = new xmldb_field('negcovar', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'effectiveweight');
b0ec60f1 146
74686047 147 /// Conditionally launch add field subqid
a4cdd6d2
PS
148 if (!$dbman->field_exists($table, $field)) {
149 $dbman->add_field($table, $field);
74686047 150 }
b0ec60f1 151
152 /// statistics savepoint reached
a4cdd6d2 153 upgrade_plugin_savepoint(true, 2008111000, 'quizreport', 'statistics');
74686047 154 }
bbf4f440 155
a4cdd6d2
PS
156 if ($oldversion < 2008112100) {
157 $DB->set_field('quiz_report', 'capability', 'quizreport/statistics:view', array('name'=>'statistics'));
b0ec60f1 158
159 /// statistics savepoint reached
a4cdd6d2 160 upgrade_plugin_savepoint(true, 2008112100, 'quizreport', 'statistics');
b0ec60f1 161 }
162
a4cdd6d2 163 return true;
9859e26c 164}
165