MDL-10107 Fixed the definition of message providers ... it now works through files...
[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
4e781c7b 81 if ($result && $oldversion < 2008072800) {
82 /// Define field completiondiscussions to be added to forum
ba6d1638 83 $table = new xmldb_table('forum');
84 $field = new xmldb_field('completiondiscussions');
ee6a5a9d 85 $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'blockperiod');
4e781c7b 86
87 /// Launch add field completiondiscussions
88 if(!$dbman->field_exists($table,$field)) {
89 $dbman->add_field($table, $field);
90 }
91
ba6d1638 92 $field = new xmldb_field('completionreplies');
93 $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiondiscussions');
4e781c7b 94
95 /// Launch add field completionreplies
96 if(!$dbman->field_exists($table,$field)) {
97 $dbman->add_field($table, $field);
98 }
99
100 /// Define field completionposts to be added to forum
ba6d1638 101 $field = new xmldb_field('completionposts');
102 $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionreplies');
4e781c7b 103
104 /// Launch add field completionposts
105 if(!$dbman->field_exists($table,$field)) {
106 $dbman->add_field($table, $field);
107 }
108 upgrade_mod_savepoint($result, 2008072800, 'forum');
109 }
90f4745c 110
111
b8a342d7 112 return $result;
113}
114
115?>