MDL-14679
[moodle.git] / mod / glossary / db / upgrade.php
CommitLineData
b8a342d7 1<?php //$Id$
ecfeb03a 2
3// This file keeps track of upgrades to
4// the glossary 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_glossary_upgrade($oldversion=0) {
21
22 global $CFG, $THEME, $db;
23
24 $result = true;
25
b8a342d7 26/// And upgrade begins here. For each one, you'll need one
27/// block of code similar to the next one. Please, delete
28/// this comment lines once this file start handling proper
ecfeb03a 29/// upgrade code.
b8a342d7 30
31/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
32/// $result = result of "/lib/ddllib.php" function calls
33/// }
baecd8cd 34
35 if ($result && $oldversion < 2006111400) {
ecfeb03a 36
b9dba084 37 /// MDL-10475, set override for legacy:student before dropping studentcanpost
38 /// if the glossary disables student postings
39
40 if ($glossaries = get_records('glossary', 'studentcanpost', '0')) {
41 foreach ($glossaries as $glossary) {
42 if ($cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
43 // add student override in this instance
44 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
45 // find all roles with legacy:student
46 if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
47 foreach ($studentroles as $studentrole) {
48 assign_capability('mod/glossary:write', CAP_PREVENT, $studentrole->id, $context->id);
49 }
50 }
51 }
52 }
53 }
54
baecd8cd 55 /// Define field studentcanpost to be dropped from glossary
56 $table = new XMLDBTable('glossary');
57 $field = new XMLDBField('studentcanpost');
58
59 /// Launch drop field studentcanpost
60 $result = $result && drop_field($table, $field);
61 }
e6d45048 62
42ff9ce6 63 if ($result && $oldversion < 2007072200) {
e6d45048 64 require_once($CFG->dirroot.'/mod/glossary/lib.php');
65 // too much debug output
66 $db->debug = false;
67 glossary_update_grades();
68 $db->debug = true;
69 }
baecd8cd 70
ecfeb03a 71 return $result;
72}
73
74?>