MDL-15498: Completion fix: provided full UTF-8 support and Excel support for progress...
[moodle.git] / mod / forum / db / upgrade.php
CommitLineData
b8a342d7 1<?php //$Id$
2
4e445355 3// This file keeps track of upgrades to
b8a342d7 4// the forum 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,
b1f93b15 18// using the methods of database_manager class
b8a342d7 19
20function xmldb_forum_upgrade($oldversion=0) {
21
219f652b 22 global $CFG, $THEME, $DB;
b8a342d7 23
4e781c7b 24 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
25
b8a342d7 26 $result = true;
27
4e445355 28/// And upgrade begins here. For each one, you'll need one
29/// block of code similar to the next one. Please, delete
b8a342d7 30/// this comment lines once this file start handling proper
31/// upgrade code.
32
33/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
b1f93b15 34/// $result = result of database_manager methods
b8a342d7 35/// }
36
f33e1ed4 37//===== 1.9.0 upgrade line ======//
f3c3a4d3 38
347037d8 39 if ($result and $oldversion < 2007101511) {
25220be3 40 notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess');
b30f2e92 41 //MDL-13866 - send forum ratins to gradebook again
42 require_once($CFG->dirroot.'/mod/forum/lib.php');
43 // too much debug output
f33e1ed4 44 $DB->set_debug(false);
b30f2e92 45 forum_update_grades();
f33e1ed4 46 $DB->set_debug(true);
04264aed 47
48 upgrade_mod_savepoint($result, 2007101511, 'forum');
b30f2e92 49 }
f3c3a4d3 50
90f4745c 51 if ($result && $oldversion < 2007101512) {
52
53 /// Cleanup the forum subscriptions
54 notify('Removing stale forum subscriptions', 'notifysuccess');
55
56 $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW);
57 $roles = array_keys($roles);
90f4745c 58
4e445355 59 list($usql, $params) = $DB->get_in_or_equal($roles);
90f4745c 60 $sql = "SELECT fs.userid, f.id AS forumid
219f652b 61 FROM {forum} f
62 JOIN {course} c ON c.id = f.course
63 JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ".CONTEXT_COURSE.")
64 JOIN {forum_subscriptions} fs ON fs.forum = f.id
4e445355 65 LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid $usql)
90f4745c 66 WHERE ra.id IS NULL";
67
4e445355 68 if ($rs = $DB->get_recordset_sql($sql, $params)) {
f33e1ed4 69 $DB->set_debug(false);
219f652b 70 foreach ($rs as $remove) {
71 $DB->delete_records('forum_subscriptions', array('userid'=>$remove->userid, 'forum'=>$remove->forumid));
90f4745c 72 echo '.';
73 }
f33e1ed4 74 $DB->set_debug(true);
ca3c8973 75 $rs->close();
90f4745c 76 }
04264aed 77
78 upgrade_mod_savepoint($result, 2007101512, 'forum');
90f4745c 79 }
4e781c7b 80
3b120e46 81 if ($result and $oldversion < 2008072401) {
82 $eventdata = new object();
83 $eventdata->modulename = 'forum';
84 $eventdata->modulefile = 'mod/forum/index.php';
85 events_trigger('message_provider_register', $eventdata);
86
87 upgrade_mod_savepoint($result, 2008072401, 'forum');
88 }
89
4e781c7b 90 if ($result && $oldversion < 2008072800) {
91 /// Define field completiondiscussions to be added to forum
92 $table = new XMLDBTable('forum');
93 $field = new XMLDBField('completiondiscussions');
94 $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'draft');
95
96 /// Launch add field completiondiscussions
97 if(!$dbman->field_exists($table,$field)) {
98 $dbman->add_field($table, $field);
99 }
100
101 $field = new XMLDBField('completionreplies');
102 $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiondiscussions');
103
104 /// Launch add field completionreplies
105 if(!$dbman->field_exists($table,$field)) {
106 $dbman->add_field($table, $field);
107 }
108
109 /// Define field completionposts to be added to forum
110 $field = new XMLDBField('completionposts');
111 $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionreplies');
112
113 /// Launch add field completionposts
114 if(!$dbman->field_exists($table,$field)) {
115 $dbman->add_field($table, $field);
116 }
117 upgrade_mod_savepoint($result, 2008072800, 'forum');
118 }
90f4745c 119
120
b8a342d7 121 return $result;
122}
123
124?>