MDL-53542 tool_lp: Fixing missed upgrade step
[moodle.git] / admin / tool / lp / db / upgrade.php
CommitLineData
4511b7d6
FM
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 * Leaning plan upgrade steps.
19 *
20 * @package tool_lp
21 * @copyright 2015 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Upgrade the plugin.
29 *
30 * @param int $oldversion
31 * @return bool always true
32 */
33function xmldb_tool_lp_upgrade($oldversion) {
34 global $CFG, $DB, $OUTPUT;
35
36 $dbman = $DB->get_manager();
37
38 if ($oldversion < 2015052403) {
39
40 // Define index idnumber (unique) to be added to tool_lp_competency_framework.
41 $table = new xmldb_table('tool_lp_competency_framework');
42 $index = new xmldb_index('idnumber', XMLDB_INDEX_UNIQUE, array('idnumber'));
43
44 // Conditionally launch add index idnumber.
45 if (!$dbman->index_exists($table, $index)) {
46 $dbman->add_index($table, $index);
47 }
48
49 // Lp savepoint reached.
50 upgrade_plugin_savepoint(true, 2015052403, 'tool', 'lp');
51 }
52
53 if ($oldversion < 2015052404) {
54
55 // Define index idnumberframework (unique) to be added to tool_lp_competency.
56 $table = new xmldb_table('tool_lp_competency');
57 $index = new xmldb_index('idnumberframework', XMLDB_INDEX_UNIQUE, array('competencyframeworkid', 'idnumber'));
58
59 // Conditionally launch add index idnumberframework.
60 if (!$dbman->index_exists($table, $index)) {
61 $dbman->add_index($table, $index);
62 }
63
64 // Lp savepoint reached.
65 upgrade_plugin_savepoint(true, 2015052404, 'tool', 'lp');
66 }
67
2de75345
FM
68 if ($oldversion < 2015052405) {
69
70 // Define field contextid to be added to tool_lp_competency_framework.
71 $table = new xmldb_table('tool_lp_competency_framework');
72 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null,
f0da26a4 73 context_system::instance()->id, 'shortname');
2de75345
FM
74
75 // Conditionally launch add field contextid.
76 if (!$dbman->field_exists($table, $field)) {
77 $dbman->add_field($table, $field);
78 }
79
80 // Lp savepoint reached.
81 upgrade_plugin_savepoint(true, 2015052405, 'tool', 'lp');
82 }
83
761a493c
FM
84 if ($oldversion < 2015052406) {
85
86 // Define field sortorder to be dropped from tool_lp_competency_framework.
87 $table = new xmldb_table('tool_lp_competency_framework');
88 $field = new xmldb_field('sortorder');
89
90 // Conditionally launch drop field sortorder.
91 if ($dbman->field_exists($table, $field)) {
92 $dbman->drop_field($table, $field);
93 }
94
95 // Lp savepoint reached.
96 upgrade_plugin_savepoint(true, 2015052406, 'tool', 'lp');
97 }
98
f0da26a4
FM
99 if ($oldversion < 2015052407) {
100
101 // Define field contextid to be added to tool_lp_template.
102 $table = new xmldb_table('tool_lp_template');
103 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null,
104 context_system::instance()->id, 'shortname');
105
106 // Conditionally launch add field contextid.
107 if (!$dbman->field_exists($table, $field)) {
108 $dbman->add_field($table, $field);
109 }
110
111 // Lp savepoint reached.
112 upgrade_plugin_savepoint(true, 2015052407, 'tool', 'lp');
113 }
114
679bce36 115 if ($oldversion < 2015052408) {
f0da26a4 116
679bce36
FM
117 // Define field sortorder to be dropped from tool_lp_template.
118 $table = new xmldb_table('tool_lp_template');
119 $field = new xmldb_field('sortorder');
120
121 // Conditionally launch drop field sortorder.
122 if ($dbman->field_exists($table, $field)) {
123 $dbman->drop_field($table, $field);
124 }
125
126 // Lp savepoint reached.
127 upgrade_plugin_savepoint(true, 2015052408, 'tool', 'lp');
128 }
761a493c 129
68e96112
DM
130 if ($oldversion < 2015052412) {
131
132 // Define table tool_lp_related_competency to be created.
133 $table = new xmldb_table('tool_lp_related_competency');
134
135 // Adding fields to table tool_lp_related_competency.
136 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
137 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
138 $table->add_field('relatedcompetencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
139 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
140 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
141 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
142
143 // Adding keys to table tool_lp_related_competency.
144 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
145
146 // Conditionally launch create table for tool_lp_related_competency.
147 if (!$dbman->table_exists($table)) {
148 $dbman->create_table($table);
149 }
150
151 // Lp savepoint reached.
152 upgrade_plugin_savepoint(true, 2015052412, 'tool', 'lp');
153 }
154
a54d5b04
FM
155 if ($oldversion < 2015052414) {
156
157 // Define field taxonomies to be added to tool_lp_competency_framework.
158 $table = new xmldb_table('tool_lp_competency_framework');
159 $field = new xmldb_field('taxonomies', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'visible');
160
161 // Conditionally launch add field taxonomies.
162 if (!$dbman->field_exists($table, $field)) {
163 $dbman->add_field($table, $field);
164 }
165
166 // Lp savepoint reached.
167 upgrade_plugin_savepoint(true, 2015052414, 'tool', 'lp');
168 }
68e96112 169
e9831af3
SG
170 if ($oldversion < 2015052416) {
171
172 // Define field idnumber to be dropped from tool_lp_template.
173 $table = new xmldb_table('tool_lp_template');
174 $field = new xmldb_field('idnumber');
175
176 // Conditionally launch drop field idnumber.
177 if ($dbman->field_exists($table, $field)) {
178 $dbman->drop_field($table, $field);
179 }
180
181 // Lp savepoint reached.
182 upgrade_plugin_savepoint(true, 2015052416, 'tool', 'lp');
183 }
184
6d57a987
SG
185 if ($oldversion < 2015052420) {
186
187 // Define table tool_lp_user_competency to be created.
188 $table = new xmldb_table('tool_lp_user_competency');
189
190 // Adding fields to table tool_lp_user_competency.
191 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
192 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
193 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
194 $table->add_field('status', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
195 $table->add_field('reviewerid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
196 $table->add_field('proficiency', XMLDB_TYPE_INTEGER, '2', null, null, null, '0');
197 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
198 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
199 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
200 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
201
202 // Adding keys to table tool_lp_user_competency.
203 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
204
205 $index = new xmldb_index('useridcompetency', XMLDB_INDEX_UNIQUE, array('userid', 'competencyid'));
206
207 // Conditionally launch create table for tool_lp_user_competency.
208 if (!$dbman->table_exists($table)) {
209 $dbman->create_table($table);
210 }
211
212 // Conditionally launch add index useridcompetency.
213 if (!$dbman->index_exists($table, $index)) {
214 $dbman->add_index($table, $index);
215 }
216
217 // Lp savepoint reached.
218 upgrade_plugin_savepoint(true, 2015052420, 'tool', 'lp');
219 }
220
8a9030c1
SG
221 if ($oldversion < 2015052423) {
222
223 // Define table tool_lp_user_competency_plan to be created.
224 $table = new xmldb_table('tool_lp_user_competency_plan');
225
226 // Adding fields to table tool_lp_user_competency_plan.
227 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
228 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
229 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
230 $table->add_field('planid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
231 $table->add_field('status', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
232 $table->add_field('reviewerid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
233 $table->add_field('proficiency', XMLDB_TYPE_INTEGER, '2', null, null, null, '0');
234 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
235 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
236 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
237 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
238
239 // Adding keys to table tool_lp_user_competency_plan.
240 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
241
242 $index = new xmldb_index('usercompetencyplan', XMLDB_INDEX_UNIQUE, array('userid', 'competencyid', 'planid'));
243
244 // Conditionally launch create table for tool_lp_user_competency_plan.
245 if (!$dbman->table_exists($table)) {
246 $dbman->create_table($table);
247 }
248
249 // Conditionally launch add index useridcompetency.
250 if (!$dbman->index_exists($table, $index)) {
251 $dbman->add_index($table, $index);
252 }
253
254 // Lp savepoint reached.
255 upgrade_plugin_savepoint(true, 2015052423, 'tool', 'lp');
256 }
257
4ad3ac34
IT
258 if ($oldversion < 2015052424) {
259
260 // Define table tool_lp_plan_competency to be created.
261 $table = new xmldb_table('tool_lp_plan_competency');
262
263 // Adding fields to table tool_lp_plan_competency.
264 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
265 $table->add_field('planid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
266 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
267 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
268 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
269 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
270 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
271
272 // Adding keys to table tool_lp_user_competency.
273 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
274
275 // Index for table tool_lp_plan_competency.
276 $index = new xmldb_index('planidcompetencyid', XMLDB_INDEX_UNIQUE, array('planid', 'competencyid'));
277
278 // Conditionally launch create table for tool_lp_plan_competency.
279 if (!$dbman->table_exists($table)) {
280 $dbman->create_table($table);
281 }
282
283 // Conditionally launch add index planidcompetencyid.
284 if (!$dbman->index_exists($table, $index)) {
285 $dbman->add_index($table, $index);
286 }
287
288 // Lp savepoint reached.
289 upgrade_plugin_savepoint(true, 2015052424, 'tool', 'lp');
290 }
291
192569ed
JPG
292 if ($oldversion < 2015052427) {
293
294 // Define fields status and reviewerid to be dropped from tool_lp_user_competency_plan.
295 $table = new xmldb_table('tool_lp_user_competency_plan');
296 $fieldstatus = new xmldb_field('status');
297 $fieldreviewerid = new xmldb_field('reviewerid');
298
299 // Conditionally launch drop field status.
300 if ($dbman->field_exists($table, $fieldstatus)) {
301 $dbman->drop_field($table, $fieldstatus);
302 }
303
304 // Conditionally launch drop field status.
305 if ($dbman->field_exists($table, $fieldreviewerid)) {
306 $dbman->drop_field($table, $fieldreviewerid);
307 }
308
309 // Lp savepoint reached.
310 upgrade_plugin_savepoint(true, 2015052427, 'tool', 'lp');
311 }
312
1896274f
FM
313 if ($oldversion < 2015111001) {
314
315 // Define field ruletype to be added to tool_lp_competency.
316 $table = new xmldb_table('tool_lp_competency');
317 $field = new xmldb_field('ruletype', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'sortorder');
318
319 // Conditionally launch add field ruletype.
320 if (!$dbman->field_exists($table, $field)) {
321 $dbman->add_field($table, $field);
322 }
323
324 // Lp savepoint reached.
325 upgrade_plugin_savepoint(true, 2015111001, 'tool', 'lp');
326 }
327
328 if ($oldversion < 2015111002) {
329
330 // Define field ruleoutcome to be added to tool_lp_competency.
331 $table = new xmldb_table('tool_lp_competency');
332 $field = new xmldb_field('ruleoutcome', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'ruletype');
333
334 // Conditionally launch add field ruleoutcome.
335 if (!$dbman->field_exists($table, $field)) {
336 $dbman->add_field($table, $field);
337 }
338
339 // Lp savepoint reached.
340 upgrade_plugin_savepoint(true, 2015111002, 'tool', 'lp');
341 }
342
343 if ($oldversion < 2015111003) {
344
345 // Define field ruleconfig to be added to tool_lp_competency.
346 $table = new xmldb_table('tool_lp_competency');
347 $field = new xmldb_field('ruleconfig', XMLDB_TYPE_TEXT, null, null, null, null, null, 'ruleoutcome');
348
349 // Conditionally launch add field ruleconfig.
350 if (!$dbman->field_exists($table, $field)) {
351 $dbman->add_field($table, $field);
352 }
353
354 // Lp savepoint reached.
355 upgrade_plugin_savepoint(true, 2015111003, 'tool', 'lp');
356 }
357
358 if ($oldversion < 2015111004) {
359
360 // Define index ruleoutcome (not unique) to be added to tool_lp_competency.
361 $table = new xmldb_table('tool_lp_competency');
362 $index = new xmldb_index('ruleoutcome', XMLDB_INDEX_NOTUNIQUE, array('ruleoutcome'));
363
364 // Conditionally launch add index ruleoutcome.
365 if (!$dbman->index_exists($table, $index)) {
366 $dbman->add_index($table, $index);
367 }
368
369 // Lp savepoint reached.
370 upgrade_plugin_savepoint(true, 2015111004, 'tool', 'lp');
371 }
372
a6ec05b6
FM
373 if ($oldversion < 2015111005) {
374
375 // Define table tool_lp_evidence to be created.
376 $table = new xmldb_table('tool_lp_evidence');
377
378 // Adding fields to table tool_lp_evidence.
379 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
380 $table->add_field('usercompetencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
381 $table->add_field('descidentifier', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
382 $table->add_field('desccomponent', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
383 $table->add_field('desca', XMLDB_TYPE_TEXT, null, null, null, null, null);
384 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
385 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
386 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
387
388 // Adding keys to table tool_lp_evidence.
389 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
390
391 // Adding indexes to table tool_lp_evidence.
392 $table->add_index('usercompetencyid', XMLDB_INDEX_NOTUNIQUE, array('usercompetencyid'));
393
394 // Conditionally launch create table for tool_lp_evidence.
395 if (!$dbman->table_exists($table)) {
396 $dbman->create_table($table);
397 }
398
399 // Lp savepoint reached.
400 upgrade_plugin_savepoint(true, 2015111005, 'tool', 'lp');
401 }
402
7d02292b
FM
403 if ($oldversion < 2015111011) {
404
405 // Define index statusduedate (not unique) to be added to tool_lp_plan.
406 $table = new xmldb_table('tool_lp_plan');
407 $index = new xmldb_index('statusduedate', XMLDB_INDEX_NOTUNIQUE, array('status', 'duedate'));
408
409 // Conditionally launch add index statusduedate.
410 if (!$dbman->index_exists($table, $index)) {
411 $dbman->add_index($table, $index);
412 }
413
414 // Lp savepoint reached.
415 upgrade_plugin_savepoint(true, 2015111011, 'tool', 'lp');
416 }
a6ec05b6 417
474090c8
FM
418 if ($oldversion < 2015111012) {
419
420 // Define table tool_lp_template_cohort to be created.
421 $table = new xmldb_table('tool_lp_template_cohort');
422
423 // Adding fields to table tool_lp_template_cohort.
424 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
425 $table->add_field('templateid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
426 $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
427 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
428 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
429 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
430
431 // Adding keys to table tool_lp_template_cohort.
432 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
433
434 // Adding indexes to table tool_lp_template_cohort.
435 $table->add_index('templateid', XMLDB_INDEX_NOTUNIQUE, array('templateid'));
436 $table->add_index('templatecohortids', XMLDB_INDEX_UNIQUE, array('templateid', 'cohortid'));
437
438 // Conditionally launch create table for tool_lp_template_cohort.
439 if (!$dbman->table_exists($table)) {
440 $dbman->create_table($table);
441 }
442
443 // Lp savepoint reached.
444 upgrade_plugin_savepoint(true, 2015111012, 'tool', 'lp');
445 }
446
6d2c2e86
FM
447 if ($oldversion < 2015111013) {
448
449 // Define field origtemplateid to be added to tool_lp_plan.
450 $table = new xmldb_table('tool_lp_plan');
451 $field = new xmldb_field('origtemplateid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'templateid');
452
453 // Conditionally launch add field origtemplateid.
454 if (!$dbman->field_exists($table, $field)) {
455 $dbman->add_field($table, $field);
456 }
457
458 // Lp savepoint reached.
459 upgrade_plugin_savepoint(true, 2015111013, 'tool', 'lp');
460 }
461
bf62b21d
FM
462 if ($oldversion < 2015111017) {
463
464 // Define field scaleid to be added to tool_lp_competency.
465 $table = new xmldb_table('tool_lp_competency');
466 $field = new xmldb_field('scaleid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'ruleconfig');
467
468 // Conditionally launch add field scaleid.
469 if (!$dbman->field_exists($table, $field)) {
470 $dbman->add_field($table, $field);
471 }
472
473 // Lp savepoint reached.
474 upgrade_plugin_savepoint(true, 2015111017, 'tool', 'lp');
475 }
476
49ae39f7
FM
477 if ($oldversion < 2015111018) {
478
479 // Define field scaleconfiguration to be added to tool_lp_competency.
480 $table = new xmldb_table('tool_lp_competency');
481 $field = new xmldb_field('scaleconfiguration', XMLDB_TYPE_TEXT, null, null, null, null, null, 'scaleid');
482
483 // Conditionally launch add field scaleconfiguration.
484 if (!$dbman->field_exists($table, $field)) {
485 $dbman->add_field($table, $field);
486 }
487
488 // Lp savepoint reached.
489 upgrade_plugin_savepoint(true, 2015111018, 'tool', 'lp');
490 }
491
4c0e8167
SG
492 if ($oldversion < 2015111020) {
493
494 // Define field url and grade to be added to tool_lp_evidence.
495 $table = new xmldb_table('tool_lp_evidence');
496 $fieldurl = new xmldb_field('url', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'desca');
497 $fieldgrade = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'url');
498
499 // Conditionally launch add field url.
500 if (!$dbman->field_exists($table, $fieldurl)) {
501 $dbman->add_field($table, $fieldurl);
502 }
503
504 // Conditionally launch add field grade.
505 if (!$dbman->field_exists($table, $fieldgrade)) {
506 $dbman->add_field($table, $fieldgrade);
507 }
508
509 // Lp savepoint reached.
510 upgrade_plugin_savepoint(true, 2015111020, 'tool', 'lp');
511 }
512
d4c0a2f6
SG
513 if ($oldversion < 2015111021) {
514
515 // Define field ruleoutcome to be added to tool_lp_course_competency.
516 $table = new xmldb_table('tool_lp_course_competency');
517 $field = new xmldb_field('ruleoutcome', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, 0, 'competencyid');
518 $index = new xmldb_index('courseidruleoutcome', XMLDB_INDEX_NOTUNIQUE, array('courseid', 'ruleoutcome'));
519
520 // Conditionally launch add field ruleoutcome.
521 if (!$dbman->field_exists($table, $field)) {
522 $dbman->add_field($table, $field);
523 }
524
525 // Conditionally launch add index ruleoutcome.
526 if (!$dbman->index_exists($table, $index)) {
527 $dbman->add_index($table, $index);
528 }
529
530 // Lp savepoint reached.
531 upgrade_plugin_savepoint(true, 2015111021, 'tool', 'lp');
532 }
533
914b580e
FM
534 if ($oldversion < 2015111022) {
535
536 // Define field contextid to be added to tool_lp_evidence.
537 $table = new xmldb_table('tool_lp_evidence');
538 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'usercompetencyid');
539
540 // Conditionally launch add field contextid.
541 if (!$dbman->field_exists($table, $field)) {
542 $dbman->add_field($table, $field);
543 }
544
545 // Lp savepoint reached.
546 upgrade_plugin_savepoint(true, 2015111022, 'tool', 'lp');
547 }
548
549 if ($oldversion < 2015111023) {
550
551 // Define field action to be added to tool_lp_evidence.
552 $table = new xmldb_table('tool_lp_evidence');
553 $field = new xmldb_field('action', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, 'contextid');
554
555 // Conditionally launch add field action.
556 if (!$dbman->field_exists($table, $field)) {
557 $dbman->add_field($table, $field);
558 }
559
560 // Lp savepoint reached.
561 upgrade_plugin_savepoint(true, 2015111023, 'tool', 'lp');
562 }
563
564 if ($oldversion < 2015111024) {
565
566 // Define field actionuserid to be added to tool_lp_evidence.
567 $table = new xmldb_table('tool_lp_evidence');
568 $field = new xmldb_field('actionuserid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'action');
569
570 // Conditionally launch add field actionuserid.
571 if (!$dbman->field_exists($table, $field)) {
572 $dbman->add_field($table, $field);
573 }
574
575 // Lp savepoint reached.
576 upgrade_plugin_savepoint(true, 2015111024, 'tool', 'lp');
577 }
578
6c2b163c
FM
579 if ($oldversion < 2015111027) {
580
581 // Define table tool_lp_user_evidence to be created.
582 $table = new xmldb_table('tool_lp_user_evidence');
583
584 // Adding fields to table tool_lp_user_evidence.
585 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
586 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
587 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
588 $table->add_field('description', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
589 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
590 $table->add_field('url', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
591 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
592 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
593 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
594
595 // Adding keys to table tool_lp_user_evidence.
596 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
597
598 // Adding indexes to table tool_lp_user_evidence.
599 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
600
601 // Conditionally launch create table for tool_lp_user_evidence.
602 if (!$dbman->table_exists($table)) {
603 $dbman->create_table($table);
604 }
605
606 // Lp savepoint reached.
607 upgrade_plugin_savepoint(true, 2015111027, 'tool', 'lp');
608 }
609
52eda876
FM
610 if ($oldversion < 2015111029) {
611
612 // Define table tool_lp_user_evidence_comp to be created.
613 $table = new xmldb_table('tool_lp_user_evidence_comp');
614
615 // Adding fields to table tool_lp_user_evidence_comp.
616 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
617 $table->add_field('userevidenceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
618 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
619 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
620 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
621 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
622
623 // Adding keys to table tool_lp_user_evidence_comp.
624 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
625
626 // Adding indexes to table tool_lp_user_evidence_comp.
627 $table->add_index('userevidenceid', XMLDB_INDEX_NOTUNIQUE, array('userevidenceid'));
628 $table->add_index('userevidencecompids', XMLDB_INDEX_UNIQUE, array('userevidenceid', 'competencyid'));
629
630 // Conditionally launch create table for tool_lp_user_evidence_comp.
631 if (!$dbman->table_exists($table)) {
632 $dbman->create_table($table);
633 }
634
635 // Lp savepoint reached.
636 upgrade_plugin_savepoint(true, 2015111029, 'tool', 'lp');
637 }
6c2b163c 638
964afa98
IT
639 if ($oldversion < 2015111030) {
640
641 // Define field visible to be removed from tool_lp_competency.
642 $table = new xmldb_table('tool_lp_competency');
643 $field = new xmldb_field('visible');
644
645 // Conditionally launch drop field visible.
646 if ($dbman->field_exists($table, $field)) {
647 $dbman->drop_field($table, $field);
648 }
649
650 // Lp savepoint reached.
651 upgrade_plugin_savepoint(true, 2015111030, 'tool', 'lp');
652 }
653
db650737
DW
654 if ($oldversion < 2015111039) {
655
656 // Define table tool_lp_module_competency to be created.
657 $table = new xmldb_table('tool_lp_module_competency');
658
659 // Adding fields to table tool_lp_module_competency.
660 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
661 $table->add_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
662 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
663 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
664 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
665 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
666 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
667 $table->add_field('ruleoutcome', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null);
668
669 // Adding keys to table tool_lp_module_competency.
670 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
671 $table->add_key('cmidkey', XMLDB_KEY_FOREIGN, array('cmid'), 'id', array('course_modules'));
672 $table->add_key('competencyidkey', XMLDB_KEY_FOREIGN, array('competencyid'), 'tool_lp_competency', array('id'));
673
674 // Adding indexes to table tool_lp_module_competency.
675 $table->add_index('cmidruleoutcome', XMLDB_INDEX_NOTUNIQUE, array('cmid', 'ruleoutcome'));
676
677 // Conditionally launch create table for tool_lp_module_competency.
678 if (!$dbman->table_exists($table)) {
679 $dbman->create_table($table);
680 }
681
682 // Lp savepoint reached.
683 upgrade_plugin_savepoint(true, 2015111039, 'tool', 'lp');
684 }
685
3c230247
FM
686 if ($oldversion < 2015111041) {
687
688 // Define field reviewerid to be added to tool_lp_plan.
689 $table = new xmldb_table('tool_lp_plan');
690 $field = new xmldb_field('reviewerid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'duedate');
691
692 // Conditionally launch add field reviewerid.
693 if (!$dbman->field_exists($table, $field)) {
694 $dbman->add_field($table, $field);
695 }
696
697 // Lp savepoint reached.
698 upgrade_plugin_savepoint(true, 2015111041, 'tool', 'lp');
699 }
700
d17cbbfb
FM
701 if ($oldversion < 2016020900) {
702
703 // Define field note to be added to tool_lp_evidence.
704 $table = new xmldb_table('tool_lp_evidence');
705 $field = new xmldb_field('note', XMLDB_TYPE_TEXT, null, null, null, null, null, 'grade');
706
707 // Conditionally launch add field note.
708 if (!$dbman->field_exists($table, $field)) {
709 $dbman->add_field($table, $field);
710 }
711
712 // Lp savepoint reached.
713 upgrade_plugin_savepoint(true, 2016020900, 'tool', 'lp');
714 }
715
af3fa58f
IT
716 if ($oldversion < 2016020901) {
717
718 // Define field note to be added to tool_lp_user_competency_plan.
719 $table = new xmldb_table('tool_lp_user_competency_plan');
720 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
721
722 // Conditionally launch add field note.
723 if (!$dbman->field_exists($table, $field)) {
724 $dbman->add_field($table, $field);
725 }
726
727 // Lp savepoint reached.
728 upgrade_plugin_savepoint(true, 2016020901, 'tool', 'lp');
729 }
730
74c9942f
SG
731 if ($oldversion < 2016020902) {
732
733 // Define index cmidcompetencyid to be added to tool_lp_module_competency.
734 $table = new xmldb_table('tool_lp_module_competency');
735 $index = new xmldb_index('cmidcompetencyid', XMLDB_INDEX_NOTUNIQUE, array('cmid', 'competencyid'));
736
737 // Conditionally launch add index cmidcompetencyid.
738 if (!$dbman->index_exists($table, $index)) {
739 $dbman->add_index($table, $index);
740 }
741
742 // Lp savepoint reached.
743 upgrade_plugin_savepoint(true, 2016020902, 'tool', 'lp');
744 }
745
d9a0d1fc
FM
746 if ($oldversion < 2016020909) {
747
748 // Define index cmidcompetencyid (unique) to be dropped form tool_lp_module_competency.
749 $table = new xmldb_table('tool_lp_module_competency');
750 $index = new xmldb_index('cmidcompetencyid', XMLDB_INDEX_NOTUNIQUE, array('cmid', 'competencyid'));
751
752 // Conditionally launch drop index cmidcompetencyid.
753 if ($dbman->index_exists($table, $index)) {
754 $dbman->drop_index($table, $index);
755 }
756
757 // Lp savepoint reached.
758 upgrade_plugin_savepoint(true, 2016020909, 'tool', 'lp');
759 }
760
761 if ($oldversion < 2016020910) {
762
763 // Define index cmidcompetencyid (unique) to be added to tool_lp_module_competency.
764 $table = new xmldb_table('tool_lp_module_competency');
765 $index = new xmldb_index('cmidcompetencyid', XMLDB_INDEX_UNIQUE, array('cmid', 'competencyid'));
766
767 // Conditionally launch add index cmidcompetencyid.
768 if (!$dbman->index_exists($table, $index)) {
769 $dbman->add_index($table, $index);
770 }
771
772 // Lp savepoint reached.
773 upgrade_plugin_savepoint(true, 2016020910, 'tool', 'lp');
774 }
775
41460929
JP
776 if ($oldversion < 2016020912) {
777
778 // Define table tool_lp_user_comp_course to be created.
779 $table = new xmldb_table('tool_lp_user_comp_course');
780
781 // Adding fields to table tool_lp_user_comp_course.
782 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
783 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
784 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
785 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
786 $table->add_field('proficiency', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
787 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
788 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
789 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
790 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
791
792 // Adding keys to table tool_lp_user_comp_course.
793 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
794
795 // Adding indexes to table tool_lp_user_comp_course.
796 $table->add_index('useridcoursecomp', XMLDB_INDEX_UNIQUE, array('userid', 'courseid', 'competencyid'));
797
798 // Conditionally launch create table for tool_lp_user_comp_course.
799 if (!$dbman->table_exists($table)) {
800 $dbman->create_table($table);
801 }
802
803 // Lp savepoint reached.
804 upgrade_plugin_savepoint(true, 2016020912, 'tool', 'lp');
805 }
806
3e0b090c
FM
807 if ($oldversion < 2016020913) {
808
809 // Changing type of field scaleconfiguration on table tool_lp_competency_framework to text.
810 $table = new xmldb_table('tool_lp_competency_framework');
811 $field = new xmldb_field('scaleconfiguration', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'scaleid');
812
813 // Launch change of type for field scaleconfiguration.
814 $dbman->change_field_type($table, $field);
815
816 // Launch change of nullability for field scaleconfiguration.
817 $dbman->change_field_notnull($table, $field);
818
819 // Lp savepoint reached.
820 upgrade_plugin_savepoint(true, 2016020913, 'tool', 'lp');
821 }
822
b9865970
IT
823 if ($oldversion < 2016020917) {
824 // Define index courseidcompetencyid (unique) to be added to tool_lp_course_competency.
825 $table = new xmldb_table('tool_lp_course_competency');
826 $index = new xmldb_index('courseidcompetencyid', XMLDB_INDEX_UNIQUE, array('courseid', 'competencyid'));
827 // Conditionally launch add index cmidcompetencyid.
828 if (!$dbman->index_exists($table, $index)) {
829 $dbman->add_index($table, $index);
830 }
831 // Lp savepoint reached.
832 upgrade_plugin_savepoint(true, 2016020917, 'tool', 'lp');
833 }
834
cf4c3eaa 835 if ($oldversion < 2016020923) {
7ba07487
DW
836
837 // Define table tool_lp_coursecompsettings to be created.
838 $table = new xmldb_table('tool_lp_coursecompsettings');
839
840 // Adding fields to table tool_lp_coursecompsettings.
841 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
842 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
843 $table->add_field('pushratingstouserplans', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
844 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
845 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
846 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
847
848 // Adding keys to table tool_lp_coursecompsettings.
849 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
35cf63d2 850 $table->add_key('courseidlink', XMLDB_KEY_FOREIGN_UNIQUE, array('courseid'), 'course', array('id'));
7ba07487
DW
851
852 // Conditionally launch create table for tool_lp_coursecompsettings.
853 if (!$dbman->table_exists($table)) {
854 $dbman->create_table($table);
855 }
856
857 // Lp savepoint reached.
cf4c3eaa 858 upgrade_plugin_savepoint(true, 2016020923, 'tool', 'lp');
7ba07487
DW
859 }
860
861
4511b7d6
FM
862 return true;
863}