removed shorttag
[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
24 $result = true;
25
4e445355 26/// And upgrade begins here. For each one, you'll need one
27/// block of code similar to the next one. Please, delete
b8a342d7 28/// this comment lines once this file start handling proper
29/// upgrade code.
30
31/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
b1f93b15 32/// $result = result of database_manager methods
b8a342d7 33/// }
34
f33e1ed4 35//===== 1.9.0 upgrade line ======//
f3c3a4d3 36
347037d8 37 if ($result and $oldversion < 2007101511) {
25220be3 38 notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess');
b30f2e92 39 //MDL-13866 - send forum ratins to gradebook again
40 require_once($CFG->dirroot.'/mod/forum/lib.php');
41 // too much debug output
f33e1ed4 42 $DB->set_debug(false);
b30f2e92 43 forum_update_grades();
f33e1ed4 44 $DB->set_debug(true);
04264aed 45
46 upgrade_mod_savepoint($result, 2007101511, 'forum');
b30f2e92 47 }
f3c3a4d3 48
90f4745c 49 if ($result && $oldversion < 2007101512) {
50
51 /// Cleanup the forum subscriptions
52 notify('Removing stale forum subscriptions', 'notifysuccess');
53
54 $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW);
55 $roles = array_keys($roles);
90f4745c 56
4e445355 57 list($usql, $params) = $DB->get_in_or_equal($roles);
90f4745c 58 $sql = "SELECT fs.userid, f.id AS forumid
219f652b 59 FROM {forum} f
60 JOIN {course} c ON c.id = f.course
61 JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ".CONTEXT_COURSE.")
62 JOIN {forum_subscriptions} fs ON fs.forum = f.id
4e445355 63 LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid $usql)
90f4745c 64 WHERE ra.id IS NULL";
65
4e445355 66 if ($rs = $DB->get_recordset_sql($sql, $params)) {
f33e1ed4 67 $DB->set_debug(false);
219f652b 68 foreach ($rs as $remove) {
69 $DB->delete_records('forum_subscriptions', array('userid'=>$remove->userid, 'forum'=>$remove->forumid));
90f4745c 70 echo '.';
71 }
f33e1ed4 72 $DB->set_debug(true);
ca3c8973 73 $rs->close();
90f4745c 74 }
04264aed 75
76 upgrade_mod_savepoint($result, 2007101512, 'forum');
90f4745c 77 }
3b120e46 78
79 if ($result and $oldversion < 2008072401) {
80 $eventdata = new object();
81 $eventdata->modulename = 'forum';
82 $eventdata->modulefile = 'mod/forum/index.php';
83 events_trigger('message_provider_register', $eventdata);
84
85 upgrade_mod_savepoint($result, 2008072401, 'forum');
86 }
87
90f4745c 88
89
b8a342d7 90 return $result;
91}
92
93?>