MDL-14569 - Remove linked tags when deleting users. (merge from 1.9)
[moodle.git] / mod / feedback / db / upgrade.php
CommitLineData
c70ad9f7 1<?php //$Id$
2
3// This file keeps track of upgrades to
4// the feedback module
5//
6// Sometimes, changes between versions involve
7// alterations to database structures and other
8// major things that may break installations.
9//
10// The upgrade function in this file will attempt
11// to perform all the necessary actions to upgrade
12// your older installtion to the current version.
13//
14// If there's something it cannot do itself, it
15// will tell you what you need to do.
16//
17// The commands in here will all be database-neutral,
18// using the functions defined in lib/ddllib.php
19
20function xmldb_feedback_upgrade($oldversion=0) {
21
22 global $CFG, $THEME, $db;
23
24 $result = true;
25
26 if ($result && $oldversion < 2007012310) {
27
28 //create a new table feedback_completedtmp and the field-definition
29 $table = new XMLDBTable('feedback_completedtmp');
30
31 $field = new XMLDBField('id');
32 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
33 $table->addField($field);
34
35 $field = new XMLDBField('feedback');
36 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
37 $table->addField($field);
38
39 $field = new XMLDBField('userid');
40 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
41 $table->addField($field);
42
43 $field = new XMLDBField('guestid');
44 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', null);
45 $table->addField($field);
46
47 $field = new XMLDBField('timemodified');
48 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
49 $table->addField($field);
50
51 $key = new XMLDBKey('PRIMARY');
52 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
53 $table->addKey($key);
54
55 $key = new XMLDBKey('feedback');
56 $key->setAttributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
57 $table->addKey($key);
58
59 $result = $result && create_table($table);
60 ////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////
62 //create a new table feedback_valuetmp and the field-definition
63 $table = new XMLDBTable('feedback_valuetmp');
64
65 $field = new XMLDBField('id');
66 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
67 $table->addField($field);
68
69 $field = new XMLDBField('course_id');
70 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
71 $table->addField($field);
72
73 $field = new XMLDBField('item');
74 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
75 $table->addField($field);
76
77 $field = new XMLDBField('completed');
78 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
79 $table->addField($field);
80
81 $field = new XMLDBField('tmp_completed');
82 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
83 $table->addField($field);
84
85 $field = new XMLDBField('value');
86 $field->setAttributes(XMLDB_TYPE_TEXT, null, null, null, false, null, null, '', null);
87 $table->addField($field);
88
89 $key = new XMLDBKey('PRIMARY');
90 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
91 $table->addKey($key);
92
93 $key = new XMLDBKey('feedback');
94 $key->setAttributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
95 $table->addKey($key);
96
97 $result = $result && create_table($table);
98 ////////////////////////////////////////////////////////////
99 }
100
101 if ($result && $oldversion < 2007050504) {
102
103 /// Define field random_response to be added to feedback_completed
104 $table = new XMLDBTable('feedback_completed');
105 $field = new XMLDBField('random_response');
106 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
107 /// Launch add field1
108 $result = $result && add_field($table, $field);
109
110 /// Define field anonymous_response to be added to feedback_completed
111 $table = new XMLDBTable('feedback_completed');
112 $field = new XMLDBField('anonymous_response');
113 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
114 /// Launch add field2
115 $result = $result && add_field($table, $field);
116
117 /// Define field random_response to be added to feedback_completed
118 $table = new XMLDBTable('feedback_completedtmp');
119 $field = new XMLDBField('random_response');
120 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
121 /// Launch add field1
122 $result = $result && add_field($table, $field);
123
124 /// Define field anonymous_response to be added to feedback_completed
125 $table = new XMLDBTable('feedback_completedtmp');
126 $field = new XMLDBField('anonymous_response');
127 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
128 /// Launch add field2
129 $result = $result && add_field($table, $field);
130
131 ////////////////////////////////////////////////////////////
132 }
133
134 if ($result && $oldversion < 2007102600) {
135 // public is a reserved word on Oracle
136
137 $table = new XMLDBTable('feedback_template');
138 $field = new XMLDBField('ispublic');
139 if (!field_exists($table, $field)) {
140 $result = $result && table_column('feedback_template', 'public', 'ispublic', 'integer', 1);
141 }
142 }
143
144
145/// And upgrade begins here. For each one, you'll need one
146/// block of code similar to the next one. Please, delete
147/// this comment lines once this file start handling proper
148/// upgrade code.
149
150/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
151/// $result = result of "/lib/ddllib.php" function calls
152/// }
153
154 return $result;
155}
156
157?>