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, |
18 | // using the functions defined in lib/ddllib.php |
19 | |
20 | function 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 |
32 | /// $result = result of "/lib/ddllib.php" function calls |
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); |
b30f2e92 |
45 | } |
f3c3a4d3 |
46 | |
90f4745c |
47 | if ($result && $oldversion < 2007101512) { |
48 | |
49 | /// Cleanup the forum subscriptions |
50 | notify('Removing stale forum subscriptions', 'notifysuccess'); |
51 | |
52 | $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW); |
53 | $roles = array_keys($roles); |
90f4745c |
54 | |
4e445355 |
55 | list($usql, $params) = $DB->get_in_or_equal($roles); |
90f4745c |
56 | $sql = "SELECT fs.userid, f.id AS forumid |
219f652b |
57 | FROM {forum} f |
58 | JOIN {course} c ON c.id = f.course |
59 | JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ".CONTEXT_COURSE.") |
60 | JOIN {forum_subscriptions} fs ON fs.forum = f.id |
4e445355 |
61 | LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid $usql) |
90f4745c |
62 | WHERE ra.id IS NULL"; |
63 | |
4e445355 |
64 | if ($rs = $DB->get_recordset_sql($sql, $params)) { |
f33e1ed4 |
65 | $DB->set_debug(false); |
219f652b |
66 | foreach ($rs as $remove) { |
67 | $DB->delete_records('forum_subscriptions', array('userid'=>$remove->userid, 'forum'=>$remove->forumid)); |
90f4745c |
68 | echo '.'; |
69 | } |
f33e1ed4 |
70 | $DB->set_debug(true); |
219f652b |
71 | $rs-close(); |
90f4745c |
72 | } |
73 | } |
74 | |
75 | |
b8a342d7 |
76 | return $result; |
77 | } |
78 | |
79 | ?> |