0d6795d7c58bcf5696d32506caf6a77c29c1a8b9
[moodle.git] / mod / quiz / report / statistics / db / upgrade.php
1 <?php
3 function xmldb_quiz_statistics_upgrade($oldversion) {
5     global $DB;
7     $dbman = $DB->get_manager();
9 //===== 1.9.0 upgrade line ======//
11     if ($oldversion < 2008072401) {
12         //register cron to run every 5 hours.
13         $DB->set_field('quiz_report', 'cron', HOURSECS*5, array('name'=>'statistics'));
15     /// statistics savepoint reached
16         upgrade_plugin_savepoint(true, 2008072401, 'quizreport', 'statistics');
17     }
19     if ($oldversion < 2008072500) {
21     /// Define field s to be added to quiz_question_statistics
22         $table = new xmldb_table('quiz_question_statistics');
23         $field = new xmldb_field('s', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'subquestion');
25     /// Conditionally launch add field s
26         if (!$dbman->field_exists($table, $field)) {
27             $dbman->add_field($table, $field);
28         }
30     /// statistics savepoint reached
31         upgrade_plugin_savepoint(true, 2008072500, 'quizreport', 'statistics');
32     }
34     if ($oldversion < 2008072800) {
36     /// Define field maxgrade to be added to quiz_question_statistics
37         $table = new xmldb_table('quiz_question_statistics');
38         $field = new xmldb_field('maxgrade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'subquestions');
40     /// Conditionally launch add field maxgrade
41         if (!$dbman->field_exists($table, $field)) {
42             $dbman->add_field($table, $field);
43         }
45     /// statistics savepoint reached
46         upgrade_plugin_savepoint(true, 2008072800, 'quizreport', 'statistics');
47     }
49     if ($oldversion < 2008072801) {
51     /// Define field positions to be added to quiz_question_statistics
52         $table = new xmldb_table('quiz_question_statistics');
53         $field = new xmldb_field('positions', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'maxgrade');
55     /// Conditionally launch add field positions
56         if (!$dbman->field_exists($table, $field)) {
57             $dbman->add_field($table, $field);
58         }
60     /// statistics savepoint reached
61         upgrade_plugin_savepoint(true, 2008072801, 'quizreport', 'statistics');
62     }
64     if ($oldversion < 2008081500) {
65     /// Changing type of field maxgrade on table quiz_question_statistics to number
66         $table = new xmldb_table('quiz_question_statistics');
67         $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'subquestions');
69     /// Launch change of type for field maxgrade
70         $dbman->change_field_type($table, $field);
72     /// statistics savepoint reached
73         upgrade_plugin_savepoint(true, 2008081500, 'quizreport', 'statistics');
74     }
76     if ($oldversion < 2008082600) {
78     /// Define table quiz_question_response_stats to be created
79         $table = new xmldb_table('quiz_question_response_stats');
81     /// Adding fields to table quiz_question_response_stats
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);
88         $table->add_field('credit', XMLDB_TYPE_NUMBER, '15, 5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
90     /// Adding keys to table quiz_question_response_stats
91         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
93     /// Conditionally launch create table for quiz_question_response_stats
94         if (!$dbman->table_exists($table)) {
95             $dbman->create_table($table);
96         }
98     /// statistics savepoint reached
99         upgrade_plugin_savepoint(true, 2008082600, 'quizreport', 'statistics');
100     }
102     if ($oldversion < 2008090500) {
103         //delete all cached results first
104         $DB->delete_records('quiz_statistics');
105         $DB->delete_records('quiz_question_statistics');
106         $DB->delete_records('quiz_question_response_stats');
107         /// Define field anssubqid to be dropped from quiz_question_response_stats
108         $table = new xmldb_table('quiz_question_response_stats');
109         $field = new xmldb_field('anssubqid');
111         /// Conditionally launch drop field subqid
112         if ($dbman->field_exists($table, $field)) {
113             $dbman->drop_field($table, $field);
114         }
116         /// Define field subqid to be added to quiz_question_response_stats
117         $field = new xmldb_field('subqid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'questionid');
119         /// Conditionally launch add field subqid
120         if (!$dbman->field_exists($table, $field)) {
121             $dbman->add_field($table, $field);
122         }
124         /// Define field aid to be added to quiz_question_response_stats
125         $field = new xmldb_field('aid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'subqid');
127         /// Conditionally launch add field aid
128         if (!$dbman->field_exists($table, $field)) {
129             $dbman->add_field($table, $field);
130         }
132     /// statistics savepoint reached
133         upgrade_plugin_savepoint(true, 2008090500, 'quizreport', 'statistics');
134     }
136     if ($oldversion < 2008111000) {
137         //delete all cached results first
138         $DB->delete_records('quiz_statistics');
139         $DB->delete_records('quiz_question_statistics');
140         $DB->delete_records('quiz_question_response_stats');
142         /// Define field anssubqid to be dropped from quiz_question_response_stats
143         $table = new xmldb_table('quiz_question_statistics');
144         /// Define field subqid to be added to quiz_question_response_stats
145         $field = new xmldb_field('negcovar', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'effectiveweight');
147         /// Conditionally launch add field subqid
148         if (!$dbman->field_exists($table, $field)) {
149             $dbman->add_field($table, $field);
150         }
152     /// statistics savepoint reached
153         upgrade_plugin_savepoint(true, 2008111000, 'quizreport', 'statistics');
154     }
156     if ($oldversion < 2008112100) {
157         $DB->set_field('quiz_report', 'capability', 'quizreport/statistics:view', array('name'=>'statistics'));
159     /// statistics savepoint reached
160         upgrade_plugin_savepoint(true, 2008112100, 'quizreport', 'statistics');
161     }
163     return true;