Merge branch 'MDL-38713-master' of git://github.com/danpoltawski/moodle
[moodle.git] / mod / assign / db / upgrade.php
CommitLineData
bbd0e548
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Upgrade code for install
19 *
20 * @package mod_assign
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25/**
26 * upgrade this assignment instance - this function could be skipped but it will be needed later
27 * @param int $oldversion The old version of the assign module
28 * @return bool
29 */
30function xmldb_assign_upgrade($oldversion) {
3f7b501e
SH
31 global $CFG, $DB;
32
33 $dbman = $DB->get_manager();
34
75f87a57 35 if ($oldversion < 2012051700) {
3f7b501e 36
12a1a0da 37 // Define field to be added to assign.
3f7b501e 38 $table = new xmldb_table('assign');
e5403f8c
DW
39 $field = new xmldb_field('sendlatenotifications', XMLDB_TYPE_INTEGER, '2', null,
40 XMLDB_NOTNULL, null, '0', 'sendnotifications');
3f7b501e 41
12a1a0da 42 // Conditionally launch add field.
3f7b501e
SH
43 if (!$dbman->field_exists($table, $field)) {
44 $dbman->add_field($table, $field);
45 }
46
47 // Assign savepoint reached.
48 upgrade_mod_savepoint(true, 2012051700, 'assign');
75f87a57 49 }
d3d1fec2 50
12a1a0da
DW
51 // Moodle v2.3.0 release upgrade line.
52 // Put any upgrade step following this.
d3d1fec2 53
94f26900
DW
54 if ($oldversion < 2012071800) {
55
12a1a0da 56 // Define field requiresubmissionstatement to be added to assign.
94f26900 57 $table = new xmldb_table('assign');
e5403f8c
DW
58 $field = new xmldb_field('requiresubmissionstatement', XMLDB_TYPE_INTEGER, '2', null,
59 XMLDB_NOTNULL, null, '0', 'timemodified');
94f26900 60
12a1a0da
DW
61 // Conditionally launch add field requiresubmissionstatement.
62
94f26900
DW
63 if (!$dbman->field_exists($table, $field)) {
64 $dbman->add_field($table, $field);
65 }
66
67 // Assign savepoint reached.
68 upgrade_mod_savepoint(true, 2012071800, 'assign');
69 }
3a66d425 70
79ed4d84
DW
71 if ($oldversion < 2012081600) {
72
12a1a0da 73 // Define field to be added to assign.
79ed4d84 74 $table = new xmldb_table('assign');
e5403f8c
DW
75 $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '2', null,
76 XMLDB_NOTNULL, null, '0', 'timemodified');
79ed4d84 77
12a1a0da 78 // Conditionally launch add field.
79ed4d84
DW
79 if (!$dbman->field_exists($table, $field)) {
80 $dbman->add_field($table, $field);
81 }
82
83 // Assign savepoint reached.
84 upgrade_mod_savepoint(true, 2012081600, 'assign');
85 }
3f7b501e 86
9e795179
DW
87 // Individual extension dates support.
88 if ($oldversion < 2012082100) {
89
259208e0 90 // Define field cutoffdate to be added to assign.
9e795179
DW
91 $table = new xmldb_table('assign');
92 $field = new xmldb_field('cutoffdate', XMLDB_TYPE_INTEGER, '10', null,
93 XMLDB_NOTNULL, null, '0', 'completionsubmit');
94
259208e0 95 // Conditionally launch add field cutoffdate.
9e795179
DW
96 if (!$dbman->field_exists($table, $field)) {
97 $dbman->add_field($table, $field);
98 }
99 // If prevent late is on - set cutoffdate to due date.
100
101 // Now remove the preventlatesubmissions column.
102 $field = new xmldb_field('preventlatesubmissions', XMLDB_TYPE_INTEGER, '2', null,
103 XMLDB_NOTNULL, null, '0', 'nosubmissions');
104 if ($dbman->field_exists($table, $field)) {
105 // Set the cutoffdate to the duedate if preventlatesubmissions was enabled.
106 $sql = 'UPDATE {assign} SET cutoffdate = duedate WHERE preventlatesubmissions = 1';
107 $DB->execute($sql);
108
109 $dbman->drop_field($table, $field);
110 }
111
e5403f8c 112 // Define field extensionduedate to be added to assign_grades.
9e795179 113 $table = new xmldb_table('assign_grades');
e5403f8c
DW
114 $field = new xmldb_field('extensionduedate', XMLDB_TYPE_INTEGER, '10', null,
115 XMLDB_NOTNULL, null, '0', 'mailed');
9e795179 116
e5403f8c 117 // Conditionally launch add field extensionduedate.
9e795179
DW
118 if (!$dbman->field_exists($table, $field)) {
119 $dbman->add_field($table, $field);
120 }
121
122 // Assign savepoint reached.
123 upgrade_mod_savepoint(true, 2012082100, 'assign');
124 }
125
12a1a0da
DW
126 // Team assignment support.
127 if ($oldversion < 2012082300) {
128
129 // Define field to be added to assign.
130 $table = new xmldb_table('assign');
6f050c7d 131 $field = new xmldb_field('teamsubmission', XMLDB_TYPE_INTEGER, '2', null,
12a1a0da
DW
132 XMLDB_NOTNULL, null, '0', 'cutoffdate');
133
134 // Conditionally launch add field.
135 if (!$dbman->field_exists($table, $field)) {
136 $dbman->add_field($table, $field);
137 }
6f050c7d 138 $field = new xmldb_field('requireallteammemberssubmit', XMLDB_TYPE_INTEGER, '2', null,
12a1a0da
DW
139 XMLDB_NOTNULL, null, '0', 'teamsubmission');
140 // Conditionally launch add field.
141 if (!$dbman->field_exists($table, $field)) {
142 $dbman->add_field($table, $field);
143 }
6f050c7d 144 $field = new xmldb_field('teamsubmissiongroupingid', XMLDB_TYPE_INTEGER, '10', null,
12a1a0da
DW
145 XMLDB_NOTNULL, null, '0', 'requireallteammemberssubmit');
146 // Conditionally launch add field.
147 if (!$dbman->field_exists($table, $field)) {
148 $dbman->add_field($table, $field);
149 }
e5403f8c
DW
150 $index = new xmldb_index('teamsubmissiongroupingid',
151 XMLDB_INDEX_NOTUNIQUE,
152 array('teamsubmissiongroupingid'));
12a1a0da
DW
153 // Conditionally launch add index.
154 if (!$dbman->index_exists($table, $index)) {
155 $dbman->add_index($table, $index);
156 }
157 $table = new xmldb_table('assign_submission');
e5403f8c
DW
158 $field = new xmldb_field('groupid', XMLDB_TYPE_INTEGER, '10', null,
159 XMLDB_NOTNULL, null, '0', 'status');
12a1a0da
DW
160 // Conditionally launch add field.
161 if (!$dbman->field_exists($table, $field)) {
162 $dbman->add_field($table, $field);
163 }
164 upgrade_mod_savepoint(true, 2012082300, 'assign');
165 }
b473171a
DW
166 if ($oldversion < 2012082400) {
167
e5403f8c 168 // Define table assign_user_mapping to be created.
b473171a
DW
169 $table = new xmldb_table('assign_user_mapping');
170
e5403f8c 171 // Adding fields to table assign_user_mapping.
b473171a 172 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
6f050c7d
EL
173 $table->add_field('assignment', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
174 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
b473171a 175
e5403f8c 176 // Adding keys to table assign_user_mapping.
b473171a 177 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
b473171a 178 $table->add_key('assignment', XMLDB_KEY_FOREIGN, array('assignment'), 'assign', array('id'));
6f050c7d 179 $table->add_key('user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
b473171a 180
e5403f8c 181 // Conditionally launch create table for assign_user_mapping.
b473171a
DW
182 if (!$dbman->table_exists($table)) {
183 $dbman->create_table($table);
184 }
185
e5403f8c 186 // Define field blindmarking to be added to assign.
b473171a 187 $table = new xmldb_table('assign');
e5403f8c
DW
188 $field = new xmldb_field('blindmarking', XMLDB_TYPE_INTEGER, '2', null,
189 XMLDB_NOTNULL, null, '0', 'teamsubmissiongroupingid');
6f050c7d 190
b473171a
DW
191 if (!$dbman->field_exists($table, $field)) {
192 $dbman->add_field($table, $field);
193 }
194
e5403f8c 195 // Define field revealidentities to be added to assign.
b473171a 196 $table = new xmldb_table('assign');
e5403f8c
DW
197 $field = new xmldb_field('revealidentities', XMLDB_TYPE_INTEGER, '2', null,
198 XMLDB_NOTNULL, null, '0', 'blindmarking');
6f050c7d 199
b473171a
DW
200 if (!$dbman->field_exists($table, $field)) {
201 $dbman->add_field($table, $field);
202 }
6f050c7d 203
e5403f8c 204 // Assignment savepoint reached.
b473171a
DW
205 upgrade_mod_savepoint(true, 2012082400, 'assign');
206 }
12a1a0da 207
e5403f8c
DW
208 // Moodle v2.4.0 release upgrade line.
209 // Put any upgrade step following this.
6b9dfe73 210
bbd0e548
DW
211 return true;
212}
213
214